简体   繁体   English

是什么决定了PHP的FilesystemIterator的顺序,我可以更改吗?

[英]What determines the order of PHP's FilesystemIterator and can I change it?

To iterate with PHP over files in a directory I do 使用PHP迭代我所做的目录中的文件

$it = new FilesystemIterator('/path/of/files/to/iterate/over');
foreach ($it as $fileinfo) {
  echo $fileinfo->getFilename();
}

But what is the order here that files are processed? 但是文件处理的顺序是什么? I did some tests but I can't seem to understand the order PHP is using. 我做了一些测试,但我似乎无法理解PHP使用的顺序。 It's the same order everytime, at least, but it is neither alphabetically, mtime, ctime or atime. 每次都是相同的顺序,至少,但它不是按字母顺序,mtime,ctime或atime。 I tried this by creating some empty files with different names, they were neither shown in their chronological creation order nor sorted alphabetically. 我通过创建一些具有不同名称的空文件来尝试这一点,它们既没有按时间顺序创建,也没有按字母顺序排序。

What order does FilesystemIterator use? FilesystemIterator使用什么顺序? And Why? 为什么? Can I change the order? 我可以更改订单吗?

As told here DirectoryIterator sort , an iterator iterates. 正如在这里讲述的DirectoryIterator排序 ,迭代器迭代。 You will need to build an array and sort it. 您需要构建一个数组并对其进行排序。

An iterator is a desing pattern used to traverse elements on a container. 迭代器是用于遍历容器上的元素的设计模式。 More here: Iterator pattern 更多这里: 迭代器模式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM