PHP FileystemIterator next () Function

PHP

Syntax:
void FilesystemIterator::next (void)
Parameters:This function does not accept any parameters.Returned value:This function does not return any value.The following programs illustrate the FilesystemIterator function::next() in PHP:Program 1:  
// Create a new file system iterator $fileItr = new FilesystemIterator (dirname ( __ FILE__ ));  
// Check if the file iterator is correct while ( $fileItr -> valid()) { // Check directory if ( $fileItr -> isDir()) { // Show filename echo $fileItr -> getFilename(). "< br >" ; } // Move to next item $fileItr -> next(); }  
?>
Output:
dashboard img webalizer xampp
Program 2:  
// Create a new file system iterator $fileItr = new FilesystemIterator (dirname ( __ FILE__ ), FilesystemIterator::KEY_AS_FILENAME);  
// Loop starts while file iterator is active while ( $fileItr -> valid()) { // Check if the file iterator is not a directory if (! $fileItr -> isDir()) { // Show key element echo $fileItr -> key(). "< br >" ; } // Move to next item $fileItr -> next(); }  
?>
Output:
applications.html bitnami.css favicon.ico engineer.PNG gfg.php index.php Sublime Text Build 3211 x64 Setup.exe
Note . The output of this function depends on the contents of the server folder.Link: https : //www.php.net/manual/en/filesystemiterator.next.php



Get Solution for free from DataCamp guru