The Note You're Voting On
dexant9t at gmail dot com ¶ 4 years ago
It matters if you are playing with a reference or with a value
Here we are working with values so working on a reference updates original variable too;
$a = 1;
$c = 22;
$b = & $a;
echo "$a, $b"; //Output: 1, 1
$b++;
echo "$a, $b";//Output: 2, 2 both values are updated
$b = 10;
echo "$a, $b";//Output: 10, 10 both values are updated
$b =$c; //This assigns value 2 to $b which also updates $a
echo "$a, $b";//Output: 22, 22
But, if instead of $b=$c you do
$b = &$c; //Only value of $b is updated, $a still points to 10, $b serves now reference to variable $c
echo "$a, $b"//Output: 10, 22