In part one of this series I introduced you to some of the SPL Iterators and how to use them. There may be times however when the provided iterators are insufficient for your needs and you’ll want to roll your own custom iterator. Luckily, SPL provides interfaces that will allow you to do just that. For an object to be traversable in a foreach loop, PHP requires that it be an instance of Traversable. You cannot however implement this interface directly (though you can use it in instaceof checks); instead you’ll need to implement either SPL’s Iterator or IteratorAggregate interfaces.
He shows you how to implement these two interfaces in your own custom classes, looping through a set of books for the Iterator example and a "getIterator" method that creates an ArrayIterator when executed. The results of both are used in foreach loops showing how they can be used just like any other iteratable variables.