PHP | FilesystemIterator key() Function Last Updated : 26 Nov, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The FilesystemIterator::key() function is an inbuilt function in PHP which is used to retrieve the key for the current file. Syntax: string FilesystemIterator::key( void ) Parameters: This function does not accept any parameters. Return Value: This function returns the pathname or filename depending on the set flags. Below programs illustrate the FilesystemIterator::key() function in PHP: Program 1: php <?php // Create new file system iterator $fileItr = new FilesystemIterator(dirname(__FILE__), FilesystemIterator::KEY_AS_FILENAME); // Loop runs for each element of file iterator foreach($fileItr as $it) { // Display the key echo $fileItr->key() . "<br>"; } ?> Output: applications.html bitnami.css dashboard favicon.ico gfg.php img index.php webalizer xampp Program 2: php <?php // Create new file system iterator $fileItr = new FilesystemIterator(dirname(__FILE__), FilesystemIterator::KEY_AS_FILENAME); // Loop runs while file iterator is valid while ($fileItr->valid()) { // Check for non directory files if (!$fileItr->isDir()) { // Display the key echo $fileItr->key() . "<br>"; } // Move to the next element $fileItr->next(); } ?> Output: applications.html bitnami.css favicon.ico gfg.php index.php Note: The output of this function depends on the content of server folder. Reference: https://www.php.net/manual/en/filesystemiterator.key.php Comment More infoAdvertise with us Next Article PHP | FilesystemIterator next() Function J jit_t Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-Iterators Similar Reads PHP | FilesystemIterator next() Function The FilesystemIterator::next() function is an inbuilt function in PHP which is used to move to the next file element. Syntax: void FilesystemIterator::next( void ) Parameters: This function does not accept any parameters. Return Value: This function does not return any value. Below programs illustra 1 min read PHP | FilesystemIterator getFlags() Function The FilesystemIterator::getFlags() function is an inbuilt function in PHP which is used to get the handling flags. Syntax: int FilesystemIterator::getFlags( void ) Parameters: This function does not accept any parameters. Return Value: This function returns an integer value representing the set of f 1 min read PHP | FilesystemIterator rewind() Function The FilesystemIterator::rewind() function is an inbuilt function in PHP which is used to rewinds back to the beginning of the file. Syntax: void FilesystemIterator::rewind( void ) Parameters: This function does not accept any parameters. Return Value: This function does not return any value. Below p 2 min read PHP | FilesystemIterator current() Function The FilesystemIterator::current() function is an inbuilt function in PHP which is used to returns the file information of the current element. Syntax: mixed FilesystemIterator::current( void ) Parameters: This function does not accept any parameters. Return Value: This function returns the filename, 1 min read PHP | FilesystemIterator setFlags() Function The FilesystemIterator::setFlags() function is an inbuilt function in PHP which is used to set the handling flags. Syntax: void FilesystemIterator::setFlags( int $flags ) Parameters: This function accepts single parameter $flags which holds the handling flags to set. Return Value: This function does 1 min read PHP | FilesystemIterator __construct() Function The FilesystemIterator::__construct() function is an inbuilt function in PHP which is used to construct a new filesystem iterator. Syntax: public FilesystemIterator::__construct( string $path, int $flags ) Parameters: This function accepts two parameters as mentioned above and described below: $path 2 min read Like