PHP/Language Basics/Variable Set Unset

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

IsSet variable

   <source lang="html4strict">

<?

  $MyVar="Hello there!";
 If(IsSet($MyVar))
   echo "The variable is set. Its value is $MyVar";

?>

      </source>
   
  


The isset() Function

   <source lang="html4strict">

<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("
"); print(isset($some_var) . "
"); $some_var = "I am set"; print(isset($some_var) . "
");

?> </body> </html>

      </source>
   
  


UnSet array element

   <source lang="html4strict">

<?

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

?>

      </source>
   
  


unset() Function

   <source lang="html4strict">

<html> <head>

    <title>Unset()</title>

</head> <body> <?php

    $authorJ = "A";
    $authorC = "B";
    $jeremy = &$authorJ;
    $charlie = &$authorC;
  
    print("$authorJ 
"); unset($jeremy); print($authorJ . " or " . $jeremy . "
"); print("$authorC
"); unset($charlie); unset($authorC); print($authorC);

?> </body> </html>

      </source>
   
  


Unset variable

   <source lang="html4strict">

<?

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

?>

      </source>