PHP Link - Confusion

I find the link in the code below is confused,

$a = 4;
$b = &$a;
var_dump($b);

$a = 10;
var_dump($b); // 10

$b = 100;
var_dump($a); // 100 but shouldn't it be 10?

The value $bis a reference to $a, and $ais never a reference to $b.

But why when I change the meaning $b. Does the value also change $a?

+4
source share
2 answers

On line: The $b = &$a;variable is $bconfigured as a reference to $a(as it points to the same memory location as $b). In this regard $b, it essentially becomes a pseudonym or other means of access and modification $a.

++ ( , ++, /).

, .

+4

$b = &$a; , , $b, $a $b .

+1

Source: https://habr.com/ru/post/1598168/


All Articles