$b is assigned a copy of $a, and in the second part, $b is assigned a reference to $a. : Variable Reference « Language Basics « PHP






$b is assigned a copy of $a, and in the second part, $b is assigned a reference to $a.

 
<?php 
$a = 5; 
$b = $a; 
$a = 7; 
echo "\$a = $a and \$b = $b\n"; 


$a = 5; 
$b = &$a; 
$a = 7; 
echo "\$a = $a and \$b = $b\n"; 
?>
  
  








Related examples in the same category

1.& operator creates a reference
2.Create a reference to a variable with the name of the constant's value.
3.Passing by Reference in PHP
4.Only named variables may be assigned by reference.
5.Passing arrays by reference