Voting

: min(one, three)?
(Example: nine)

The Note You're Voting On

ahmad dot mayahi at gmail dot com
5 years ago
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; // The key is a number
$files[] = $item;
}

echo
$files[0]->getFilename(); // nothing happens here, you do need to use clone $item inside the foreach

?>

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.

<< Back to user notes page

To Top