This is a question of curiosity about the reasons behind the way foreach
is implemented within PHP.
Consider:
$arr = array(1,2,3);
foreach ($arr as $x) echo current($arr) . PHP_EOL;
which will output:
2
2
2
I understand that foreach
rewinds array pointers to the beginning; however, why does it then increment it only once? What is happening inside the magic box?? Is this just an (ugly) artefact?
Thanks @NickC -- for anyone else curious about zval
and refcount
, you can read up on the basics here