Many developers get confused between DirectoryIterator and FilesystemIterator, there are a few small differences that I'm goning to list them here:
DirectoryIterator:
* Includes the "." and ".." within the path.
* Numberd keys.
* Path is not included in in value.
* No configuration available.
* You do need to use "clone" when storing the elements into an array.
Example:
<?php
$files = [];
foreach ($dir as $key => $item) {
echo $key.PHP_EOL; $files[] = $item;
}
echo $files[0]->getFilename(); ?>
FilesystemIterator:
* Dot files skipped.
* Pathname is used as a key as well as a value.
* Configurable.
* Uses SplFileInfo to store the files.
"FilesystemIterator" it's an enhanced version of DirectoryIterator, and I prefer to use it instead of the DirectoryIterator.