phpinfinite-looparrayiterator

Why iterating over ArrayIterator ending with endless loop?


Array in my code is quite big so I pasting it in pastebin. http://pastebin.com/6tviT2Xj

I don't understand why I am getting endless loop

Logic of this script is:

$it = new ArrayIterator($options);
while($it->valid()) {
    print $it->key();
    print $it->current();
}

Solution

  • Because you never move in you iterator (with ArrayIterator::next()).

    while ($it->valid()) {
        ...
        $it->next();
    }