PHP DirectoryIterator valid () function

PHP

Syntax:
bool DirectoryIterator::valid (void)
Parameters:this function takes no parameters.Return value:this function returns TRUE if the position is correct, otherwise it returns FALSE.The following programs illustrate the DirectoryIterator::valid() function in PHP:Program 1:  
// Create an Iterator directory $directory = new DirectoryIterator (dirname ( __ FILE__ ));  
// Move to third element $directory -> seek (2);  
// Check if the catalog item is correct if ( $directory -> valid()) { // Show file name echo $directory -> getFilename(); }  
?>
Output:
applications.html
Program 2:  
// Create an Iterator directory $directory = new DirectoryIterator (dirname ( __ FILE__ ));  
// Loop while the directory is valid while ( $directory -> valid()) { // Validate a catalog item if ( $directory -> isDir()) { // Show key and file name echo $directory -> key(). "= >" . $directory -> getFilename(). "< br >" ; } // Move to next item $directory -> next(); }  
?>
Output:
0 = > ... 1 = > .. 4 = > dashboard 8 = > img 11 = > webalizer 12 = > xampp
Note . The output of this function depends on the contents of the server folder.Link: https : //www.php.net/manual/en/directoryiterator.valid.php