$test = array(1, 2, 3, 4, 5);
foreach($test as $element)
{
echo $element;
$element = next($test);
echo $element;
}
This produces the output “122334455” in PHP 5.2.0
The output “13243545” is produced in PHP 5.3.3
How do I reproduce the output of 5.2.0 in 5.3.3 most efficiently by means of controlling the iterator?
This may be a bug as the iterator works in 5.2 inside the foreach, but not in 5.3’s foreach.
It seems a bug related with PHP. You can use a more explanatory “for” loop: