Possible Duplicate:
Strange behavior Of foreach
Strange behaviour after loop by reference - Is this a PHP bug?
I do have a problem with Foreach, I can't understand the second foreach.
why the third part of $foo array has 'two' in its value!
In as much as we know, if we remove the '&'(in first foreach) the problem will solve, but why?
<?php
$foo = array('one', 'two', 'three');
foreach ($foo as &$bar)
{
// no-op
}
var_dump($foo);
foreach ($foo as $bar)
{
// no-op
}
var_dump($foo);
?>
###############################################
produces:
array(3) {
[0]=>string(3) "one"
[1]=>string(3) "two"
[2]=>&string(5) "three"
}
array(3) {
[0]=>string(3) "one"
[1]=>string(3) "two"
[2]=>&string(3) "two"
}