PHP/Language Basics/Variable Set Unset

Материал из Web эксперт
Перейти к: навигация, поиск

IsSet variable

<?
   $MyVar="Hello there!";

  If(IsSet($MyVar))
    echo "The variable is set. Its value is $MyVar";
?>



The isset() Function

<html>
<head>
     <title>Isset()</title>
</head>
<body>
<?php
     $my_var = 100;
   
     if(isset($my_var)) {
          print("\$my_var is set... the value is " . $my_var);
     }
   
     print("<br/>");
     print(isset($some_var) . "<br />");
   
     $some_var = "I am set";
     print(isset($some_var) . "<br />");
?>
</body>
</html>



UnSet array element

<?
 $A=array(0=>"zzzz", 
          "a"=>"aaa", 
          "b"=>"bbb", 
          "c"=>"ccc");
 Unset($A["a"]);
 echo $A["a"]
?>



unset() Function

<html>
<head>
     <title>Unset()</title>
</head>
<body>
<?php
     $authorJ = "A";
     $authorC = "B";
     $jeremy = &$authorJ;
     $charlie = &$authorC;
   
     print("$authorJ <br/>");
     unset($jeremy);
     print($authorJ . " or " . $jeremy . "<br />");
   
     print("$authorC <br />");
     unset($charlie);
     unset($authorC);
     print($authorC);
?>
</body>
</html>



Unset variable

<?
   $a="Hello there!";
   echo $a
   unset($a);
   echo $a; // Error: there is no variable $a
?>