this code produces unexpected output:
$array=str_split("abcde"); foreach($array as &$item) echo $item; echo "\n"; foreach($array as $item) echo $item;
exit:
abcde abcdd
if you use &$item for the second loop, everything works fine.
I do not understand how this code will affect the contents of $array . I might think that an implicit unset($header) will delete the last line, but where does double dd come from?
arrays pass-by-reference php foreach
Frederic bazin
source share