As per the php code below, the output is
1 . 1
2 . 2
3 . 3
I understand &$ref is passing by reference. but its like after the assignment($row = &$ref;) everywhere whenever 'row' changes the value, 'ref' changes as the same value as 'row' too. really confusing. Seems like that = is not only assign the right value to the left. Can someone please verify this?
<?php
$ref = 0;
$row = &$ref;
foreach (array(1, 2, 3) as $row) {
print "$row . $ref \n" ;
}
echo $ref;
?>
When you do $row = &$ref;
It means: the same variable content with another name. That is, the same, not a copy. What you do in $ref
, it will be made in $row
... and vice versa.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With