在windows中,当我们看到文件夹的详细视图和按名称排序时,我想要完全相同的序列
在windows中我按顺序获得LEU2G0014L1A01.pdf,但是通过我的代码,我首先得到LEU2G001041B01.pdf数组中的任何解决方案。?
<?php
$dir = "A/";
$result = find_all_files($dir);
sort($result);
print_r($result);
function find_all_files($dir)
{
$root = scandir($dir);
foreach($root as $value)
{
if($value === '.' || $value === '..') {continue;}
if(is_file("$dir/$value")) {$result[]="$value";continue;}
foreach(find_all_files("$dir/$value") as $value)
{
$result[]=$value;
}
}
return $result;
}
?>
答案 0 :(得分:1)
答案 1 :(得分:0)
考虑从php手册网站获得的以下示例: http://www.php.net/manual/en/function.scandir.php
<?php
$dir = "/tmp";
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
sort($files);
print_r($files);
rsort($files);
print_r($files);
?>
产生以下输出:
Array
(
[0] => .
[1] => ..
[2] => bar.php
[3] => foo.txt
[4] => somedir
)
Array
(
[0] => somedir
[1] => foo.txt
[2] => bar.php
[3] => ..
[4] => .
)