PHP/Language Basics/Reference

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

Assigning a Variable by Reference

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



Assign reference to a variable

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



unset reference variables

<?php
     $a = "AAA";
     $b = &$a;
     $c = &$b;
   
     print($a . "<br />");
     unset($b);
     print($c . "<br />");
?>



Variable References Demo

<?php
     $my_foo = "A";
     $my_bar = &$my_foo;
     $my_foo = "B";
   
     print($my_bar);
   
     $my_bar = "C";
     print($my_foo);
?>