php8.5
Home/ Manual/ spl / directoryiterator/ DirectoryIterator::seek

DirectoryIterator::seek

PHP function Edit on GitHub ✎

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

Seek to a DirectoryIterator item

Description

DirectoryIterator::seek(int $offset): void

Seek to a given position in the DirectoryIterator.

Parameters

offset

The zero-based numeric position to seek to.

Return Values

Void

Examples

DirectoryIterator::seek example

Seek to the fourth item in the directory containing the script. The first two are usually . and ..

php
<?php
$iterator = new DirectoryIterator(dirname(__FILE__));
$iterator->seek(3);
if ($iterator->valid()) {
    echo $iterator->getFilename();
} else {
    echo 'No file at position 3';
}
?>

See Also

  • DirectoryIterator::rewind
  • DirectoryIterator::next
  • SeekableIterator::seek

Source: reference/spl/directoryiterator/seek.xml · from the official PHP manual (php/doc-en)