What are PHP iterators and the Iterator/IteratorAggregate interfaces used for?
Last updated
Iterators let an object define how
foreachtraverses it, hiding internal storage behind an array-like interface.Iteratorrequires five methods (current(),key(),next(),rewind(),valid()) for full control over lazy or custom traversal.IteratorAggregateneeds onlygetIterator(), returning an existing iterator such asArrayIteratoror a generator.