PHP | DirectoryIterator rewind() Function Last Updated : 26 Nov, 2019 Comments Improve Suggest changes Like Article Like Report The DirectoryIterator::rewind() function is an inbuilt function in PHP which is used to rewind the DirectoryIterator back to the start position. Syntax: void DirectoryIterator::rewind( void ) Parameters: This function does not accept any parameters. Return Value: This function does not return any value. Below programs illustrate the DirectoryIterator::rewind() function in PHP: Program 1: php <?php // Create a directory Iterator $directory = new DirectoryIterator(dirname(__FILE__)); // Loop runs while directory is valid while ($directory->valid()) { // Check the element is directory if($directory->isDir()) { // Display the key and file name echo $directory->key() . " => " . $directory->getFilename() . "<br>"; } // Move to the next element $directory->next(); } // Use rewind() function to move to // the start position $directory->rewind(); // Display the key and file name echo $directory->key() . " => " . $directory->getFilename(); ?> Output: 0 => . 1 => .. 4 => dashboard 8 => img 11 => webalizer 12 => xampp 0 => . Program 2: php <?php // Create a directory Iterator $directory = new DirectoryIterator(dirname(__FILE__)); // Loop runs for each element of directory foreach($directory as $dir) { // Display key and file name echo $dir->key() . " => " . $dir->getFilename() . "<br>"; } // Use rewind() function to move to // the start position $directory->rewind(); // Display key and file name echo $directory->key() . " => " . $directory->getFilename(); ?> Output: 0 => . 1 => .. 2 => applications.html 3 => bitnami.css 4 => dashboard 5 => favicon.ico 6 => geeks.PNG 7 => gfg.php 8 => img 9 => index.php 10 => Sublime Text Build 3211 x64 Setup.exe 11 => webalizer 12 => xampp 0 => . Note: The output of this function depends on the content of server folder. Reference: https://www.php.net/manual/en/directoryiterator.rewind.php Comment More infoAdvertise with us Next Article PHP | DirectoryIterator rewind() Function J jit_t Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-Iterators Similar Reads PHP | DirectoryIterator valid() Function The DirectoryIterator::valid() function is an inbuilt function in PHP which is used to check the current DirectoryIterator position is a valid file or not. Syntax: bool DirectoryIterator::valid( void ) Parameters: This function does not accept any parameters. Return Value: This function returns TRUE 1 min read PHP | DirectoryIterator seek() Function 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 t 1 min read PHP | DirectoryIterator __toString() Function The DirectoryIterator::__toString() function is an inbuilt function in PHP which is used to return the file name of the current DirectoryIterator item.Syntax:Â string DirectoryIterator::__toString( void ) Parameters: This function does not accept any parameters.Return Value: This function returns th 2 min read PHP | ArrayIterator rewind() Function The ArrayIterator::rewind() function is an inbuilt function in PHP which is used to rewind the array back to the start. Syntax: void ArrayIterator::rewind( void ) Parameters: This function does not accept any parameters. Return Value: This function does not return any value. Below programs illustrat 1 min read PHP | DirectoryIterator key() Function The DirectoryIterator::key() function is an inbuilt function in PHP which is used to return the key for the current DirectoryIterator item. Syntax: string DirectoryIterator::key( void ) Parameters: This function does not accept any parameters. Return Value: This function returns the key for the curr 2 min read Like