Every variable is a reference to a value. Normally the value is copied when you use it, but with &
the reference is copied.
Suppose you have the following variable:
$original = 'john';
If you assign the value from $datasql to a variable, that value is copied:
$text = $original;
If you assign a reference, the value is not copied but referenced:
$text = & $original;
This means that $text
points to the value of $original
. Now, if you unset $original
, the contents of $text
are still valid:
unset($original);
echo $text; // john
This is because PHP knows there is still a reference to the value of $original
, so it deletes the $original
variable as name, but not the contents.
Your example is similar, except that the variable is not explicitly unset, but overwritten. It is a reference to a value, just like any other variable.