SeekableIterator¶
SeekableIterator extends the Iterator interface by adding a seek(int $offset) method to jump directly to a specific position without iterating through preceding elements.
It is implemented by ArrayIterator and SplFixedArray. Attempting to seek to an invalid position should throw an OutOfBoundsException.
<?php
$iterator = new ArrayIterator(['a', 'b', 'c', 'd', 'e']);
$iterator->seek(3);
echo $iterator->current(); // d
?>
See also SeekableIterator Class.
Related : Iterator, Interface, Standard PHP Library (SPL), PHP Native Interfaces, SplSubject
Added in PHP 5.1