This is the code that I don't understand (as the output).
<?php
$x = ['test1', 'test2', 'test3', 'test4'];
echo "First FOREACH\n";
foreach ($x as &$y)
{
echo $y."\n";
}
echo "\n\nSecond FOREACH\n";
foreach ($x as $y)
{
echo $y."\n";
}
?>
Output:
First FOREACH
test1
test2
test3
test4
Second FOREACH
test1
test2
test3
test3
PS: I'm running it under:
php -v
PHP 5.6.11-1ubuntu3.1 (cli)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies