Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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

?>

Documentation

See Also