PHP SPL RegexIterator how files would be ordered?

限于喜欢 提交于 2019-12-11 17:15:09

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!