PHP | DirectoryIterator seek() Function Last Updated : 26 Nov, 2019 Comments Improve Suggest changes Like Article Like Report 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 <?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(); } ?> Output: applications.html Program 2: php <?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(); } ?> 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 Create Quiz Comment J jit_t Follow 0 Improve J jit_t Follow 0 Improve Article Tags : Web Technologies PHP PHP-function PHP-Iterators Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like