Because on the second loop, $v
is still a reference to the last array item, so it's overwritten each time.
You can see it like that:
$a = array ('zero','one','two', 'three');
foreach ($a as &$v) {
}
foreach ($a as $v) {
echo $v.'-'.$a[3].PHP_EOL;
}
As you can see, the last array item takes the current loop value: 'zero', 'one', 'two', and then it's just 'two'... : )