+

PHP FileystemIterator Key () Function

Syntax:
string FilesystemIterator::key (void)
Parameters:This function takes no parameters.Return Value:This function returns the path or filename depending on the flags set.The following programs illustrate the FilesystemIterator::key() function in PHP:Program 1:  
// Create a new file system iterator $fileItr = new FilesystemIterator (dirname ( __ FILE__ ), Filesystem Iterator::KEY_AS_FILENAME);  
// loop is performed for each element of the file iterator foreach ( $fileItr as $it ) { // Show key echo $fileItr -> key(). "< br >" ; }  
?>
Output:
applications.html bitnami.css dashboard favicon.ico gfg.php img index.php 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 for files outside the directory if (! $fileItr -> isDir() ) { // Show key echo $fileItr -> key(). "< br >" ; } // Move to next item $fileItr -> next(); }  
?>
Output:
applications.html bitnami.css favicon.ico gfg.php index.php
Note . The output of this function depends on the contents of the server folder.Link: https : //www.php.net/manual/en/filesystemiterator.key.php
Get Solution for free from DataCamp guru