Iterator

An iterator is an object which can be traversed with a foreach() loop.

Iterator is an interface, which shall be implemented by objects. There are also a list of default iterators in the SPL extension.

An iterator may be turned into an array, with the iterator_to_array() function. Arrays may be used as iterator natively, or used as an objet with the ArrayObject class.

<?php

    class myIterator implements Iterator { /**/ }

    $it = new myIterator;

    foreach($it as $key => $value) {
        var_dump($key, $value);
        echo "\n";
    }

?>

Documentation

See also Modern PHP Developer - Iterator and Iterator in PHP.

Related : Standard PHP Library (SPL), Traversal, foreach(), ArrayObject, DirectoryIterator, iterator_to_array(), PHP Native Interfaces, RecursiveIterator, IteratorAggregate, OuterIterator, RecursiveArrayIterator, RecursiveDirectoryIterator, SeekableIterator, SplDoublyLinkedList, SplFileObject, SplObjectStorage