Foreach Iterator Behavioral Difference in PHP 5.2.0 versus PHP 5.3.3 -
$test = array(1, 2, 3, 4, 5); foreach($test $element) { echo $element; $element = next($test); echo $element; }
this produces output "122334455" in php 5.2.0 output "13243545" produced in php 5.3.3
how reproduce output of 5.2.0 in 5.3.3 efficiently means of controlling iterator?
this may bug iterator works in 5.2 inside foreach, not in 5.3's foreach.
it seems bug related php. can use more explanatory "for" loop:
$c = count($test); for($i=0; $i < $c; $i++) { echo $test[$i]; if(isset($test[$i+1])) { echo $test[$i+1]; } else { echo $test[$i]; } }
Comments
Post a Comment