The Iterator interfaceIntroductionInterface for external iterators or objects that can be iterated themselves internally. Interface synopsis
Iterator
extends
Traversable
/* Methods */
public mixed Iterator::current()
public mixed Iterator::key()
public void Iterator::next()
public void Iterator::rewind()
public bool Iterator::valid()
Predefined iteratorsPHP already provides a number of iterators for many day to day tasks. See SPL iterators for a list. ExamplesExample #1 Basic usage This example demonstrates in which order methods are called when using foreach with an iterator.
The above example will output something similar to: string(18) "myIterator::rewind" string(17) "myIterator::valid" string(19) "myIterator::current" string(15) "myIterator::key" int(0) string(12) "firstelement" string(16) "myIterator::next" string(17) "myIterator::valid" string(19) "myIterator::current" string(15) "myIterator::key" int(1) string(13) "secondelement" string(16) "myIterator::next" string(17) "myIterator::valid" string(19) "myIterator::current" string(15) "myIterator::key" int(2) string(11) "lastelement" string(16) "myIterator::next" string(17) "myIterator::valid" See AlsoSee also object iteration.
|