<?php
$a = array(1, 2, 3, 4, 5);
foreach ($a as $key => $elem) {
echo "$key = $elem"; echo ' = ';
var_dump(current($a));\
}
?>
The output I get when running that is as follows:
0 = 1 = int(2)
1 = 2 = int(2)
2 = 3 = int(2)
3 = 4 = int(2)
4 = 5 = int(2)
Seems to me that this is the output I should be getting?:
0 = 1 = int(1)
1 = 2 = int(2)
2 = 3 = int(3)
3 = 4 = int(4)
4 = 5 = int(5)
I do current() before the for loop on $a and get int(1). Thus it seems like it's the foreach loop that's causing it to increment. But if that's the case why is it only doing it once?
If I call next() in the for loop it increments but not otherwise. Of course next() starts out at int(3) (ie. the value after int(2))..