DirectoryIterator¶
The DirectoryIterator class provides a simple interface for viewing the contents of filesystem directories.
<?php
$iterator = new DirectoryIterator(__DIR__);
while($iterator->valid()) {
$file = $iterator->current();
echo $iterator->key() . " => " . $file->getFilename() . "\n";
$iterator->next();
}
?>
Related : Iterator, Standard PHP Library (SPL)