& operator creates a reference : Variable Reference « Language Basics « PHP






& operator creates a reference

 
<?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.$b is assigned a copy of $a, and in the second part, $b is assigned a reference to $a.
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