Recently I experienced this weird problem:
while(list($key, $value) = each($array))
was not listing all array values, where replacing it with…
foreach($array as $key => $value)
…worked perfectly.
And, I’m curious now.. what is the difference between those two?
Had you previously traversed the array?
each()remembers its position in the array, so if you don’treset()it you can miss items.For what it’s worth this method of array traversal is ancient and has been superseded by the more idiomatic foreach. I wouldn’t use it unless you specifically want to take advantage of its one-item-at-a-time nature.
(Source: PHP Manual)