PHP DirectoryIterator current () function

PHP

Syntax:
DirectoryIterator DirectoryIterator::current (void)
Parameters:This function takes no parameters.Return value:This function returns the current DirectoryIterator item.The following programs illustrate the DirectoryIterator function::current() in PHP:Program 1:  
// 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()) { // Save the current element $file = $directory -> current(); // Show filename echo $file -> getFilename(). "< br >" ; } // Move to next item $directory -> next(); }
?>
Output:
. .. dashboard img webalizer xampp
Program 2:  
// Create an Iterator directory $directory = new DirectoryIterator (dirname (< / code> __ FILE__ ));  
// Loop for each directory item foreach ( $directory as $dir ) { // Save current element $file = $directory -> current(); // Show key and file name echo $dir -> key(). "= >" . $file -> getFilename(). "< br >" ; }
?>
Output:
0 = > ... 1 = > .. 2 = > applications.html 3 = > bitnami.css 4 = > dashboard 5 = > favicon.ico 6 = > engineer.PNG 7 = > gfg.php 8 = > img 9 = > index.php 10 = > Sublime Text Build 3211 x64 Setup.exe 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.current.php



Get Solution for free from DataCamp guru