I’m trying to understand passing by reference. This is probably a bad analogy, but is it like Newton’s 3rd law (action-reaction pairs)?
For example, for the following code
$a = 4;
$b = 2;
$n = 42;
$a = &$b;
is
$a=$n the same as $b=$n? Isn’t the value of $a and $b stored in the same address?
If you assign these variables normally:
Then the associations will look like this:
Now, if you make
$cinto a reference of$a, like this:Then the associations will look like this:
In other words,
$aand$cpoint to the same value. Because they both point to the same value we can change either of the variables and they will both point to the new value.