问题
Let's say I have a snippet:
<?php
$directoryIterator = new RecursiveDirectoryIterator('some_dir_here');
$iteratorIterator = new RecursiveIteratorIterator($directoryIterator);
$regexp = '/hello_world[\d]*/';
$fileList = new RegexIterator($iteratorIterator, $regexp);
foreach ($fileList as $file) {
echo $file . PHP_EOL;
}
It gets all files from some_dir_here
, which match regexp.
How would be files in $fileList
ordered (for example: by name ascending)? Are there any proofs in official docs?
回答1:
RecursiveDirectoryIterator uses opendir, which doesn't sort its results.
If you want sorted results, you can use scandir, but it's not recursive or iterative.
来源:https://stackoverflow.com/questions/57685464/php-spl-regexiterator-how-files-would-be-ordered