PHP/Language Basics/Reference

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

Assigning a Variable by Reference

   <source lang="html4strict">

<html> <head> <title>Assigning a variable by reference</title> </head> <body> <?php $aVariable = 42; $anotherVariable = &$aVariable; $aVariable= 325; print $anotherVariable; ?>

</body>

</html>

      </source>
   
  


Assign reference to a variable

   <source lang="html4strict">

<?php

  $value1 = "Hello";
  $value2 =& $value1; /* $value1 and $value2 both equal "Hello". */
  $value2 = "Goodbye"; /* $value1 and $value2 both equal "Goodbye". */
  echo($value1);
  echo($value2);

?>

      </source>
   
  


unset reference variables

   <source lang="html4strict">

<?php

    $a = "AAA";
    $b = &$a;
    $c = &$b;
  
    print($a . "
"); unset($b); print($c . "
");

?>

      </source>
   
  


Variable References Demo

   <source lang="html4strict">

<?php

    $my_foo = "A";
    $my_bar = &$my_foo;
    $my_foo = "B";
  
    print($my_bar);
  
    $my_bar = "C";
    print($my_foo);

?>

      </source>