PHP SPL RegexIterator如何对文件进行排序? [英] PHP SPL RegexIterator how files would be ordered?

查看:96
本文介绍了PHP SPL RegexIterator如何对文件进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个摘要:

<?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;
}

它从some_dir_here获取与正则表达式匹配的所有文件.

It gets all files from some_dir_here, which match regexp.

$fileList中的文件如何排序(例如:按名称升序)?官方文档中有任何证据吗?

How would be files in $fileList ordered (for example: by name ascending)? Are there any proofs in official docs?

推荐答案

RecursiveDirectoryIterator 使用 opendir ,对结果进行排序.

RecursiveDirectoryIterator uses opendir, which doesn't sort its results.

如果要对结果进行排序,可以使用 scandir ,但它不是递归的或迭代的.

If you want sorted results, you can use scandir, but it's not recursive or iterative.

这篇关于PHP SPL RegexIterator如何对文件进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆