PHP | DirectoryIterator seek() Function
Last Updated :
26 Nov, 2019
The DirectoryIterator::seek() function is an inbuilt function in PHP which is used to seek the DirectoryIterator item to the given position.
Syntax:
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
$directory = new DirectoryIterator(dirname( __FILE__ ));
$directory ->seek(2);
if ( $directory ->valid()) {
echo $directory ->getFilename();
}
?>
|
Output:
applications.html
Program 2:
<?php
$directory = new DirectoryIterator(dirname( __FILE__ ));
$directory ->seek(2);
if ( $directory ->valid()) {
echo $directory ->key() . " => " .
$directory ->getFilename();
}
?>
|
Output:
2 => applications.html
Note: The output of this function depends on the content of server folder.
Reference: https://www.php.net/manual/en/directoryiterator.seek.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...