The DirectoryIterator::seek() function is an inbuilt function in PHP which is used to seek the DirectoryIterator item to the given position.
Syntax:
php
Output:
php
Output:
void DirectoryIterator::seek( int $position )Parameters: This function accept single parameter $position which holds the zero-based numeric position to seek the element. Return Value: This function does not return any value. Below programs illustrate the DirectoryIterator::seek() function in PHP: Program 1:
<?php
// Create a directory Iterator
$directory = new DirectoryIterator(dirname(__FILE__));
// Move to the third element (0 based indexing)
$directory->seek(2);
// Check for validity of element
if($directory->valid()) {
// Display the filename
echo $directory->getFilename();
}
?>
applications.htmlProgram 2:
<?php
// Create a directory Iterator
$directory = new DirectoryIterator(dirname(__FILE__));
// Move to the third element (0 based indexing)
$directory->seek(2);
// Check for validity of element
if($directory->valid()) {
// Display the key and filename
echo $directory->key() . " => " .
$directory->getFilename();
}
?>
2 => applications.htmlNote: The output of this function depends on the content of server folder. Reference: https://www.php.net/manual/en/directoryiterator.seek.php