Possible Duplicate:
Strange behaviour after loop by reference - Is this a PHP bug?
Consider this code:
$start = array("a", "b", "c");
foreach ($start as &$item) {}
foreach ($start as $item) {}
print_r($start);
When I foreach over the array and use the elements as reference, and then foreach again, but this time using normal variables, but keeping the same variable name as the refrence's, the last element of the input array is overwritten with the contents of the previous one.
The above code outputs:
Array
(
[0] => a
[1] => b
[2] => b
)
Could anyone explain me why this happens? I imagine it's a memory addressing issue, but can't find any logic in this phenomenon. What exactly goes on behind the scenes here?