TIA。凭借我的 PHP 补救技能,我无法弄清楚为什么 scandir 不能按字母顺序自动排序。 (将文件夹组合在一起并按字母顺序排序以及将文件组合在一起并按字母顺序排序也很好,但这并不重要。)我错过了什么?
<?php
$dir = './customers/' . $customer . "/";
$exclude = array(".","..",".htaccess");
if (is_dir($dir)) {
$files = scandir($dir);
foreach($files as $key=>$dir){
if(!in_array($dir, $exclude)){
echo ("<a href=\"./customers/$customer/".$dir."\">".$dir."</a><br>");
}
}
}
?>
最佳答案
正如WGD所说,你必须使用natcasesort通过以下方式:
$files = scandir($dir);
natcasesort($files);
foreach ($files as $file) {
// your code
}
关于PHP Scandir 不是按字母顺序自动排列的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16627471/