Php scnadir排序顺序asc将大写字母放在第一位
因此,我试图对文件夹和文件列表进行排序,并按字母顺序显示。问题是,如果有人创建了一个以大写字母开头的文件夹,那么该文件夹将首先显示,例如,如果我有以下文件夹Php scnadir排序顺序asc将大写字母放在第一位,php,sorting,scandir,Php,Sorting,Scandir,因此,我试图对文件夹和文件列表进行排序,并按字母顺序显示。问题是,如果有人创建了一个以大写字母开头的文件夹,那么该文件夹将首先显示,例如,如果我有以下文件夹 Array ( [0] => . [1] => .. [2] => _base [3] => template [4] => Website ) 我希望在使用scandir(scandir($directory,scandir\u SORT\u ASCENDING))时
Array
(
[0] => .
[1] => ..
[2] => _base
[3] => template
[4] => Website
)
我希望在使用scandir(scandir($directory,scandir\u SORT\u ASCENDING)
)时,可以看到上面列出的文件夹,而不是下面列出的文件夹
Array
(
[0] => .
[1] => ..
[2] => Website
[3] => _base
[4] => template
)
我如何才能正确排序此列表,使其不区分大小写。也许您应该使用函数
例如:
$x = array('.', '..', '22331', 'djsnaso', 'Aijndod', 'Wwwwww');
sort($x);
var_dump($x);
返回值:
array (size=6)
0 => string '.' (length=1)
1 => string '..' (length=2)
2 => string '22331' (length=5)
3 => string 'Aijndod' (length=7)
4 => string 'Wwwwww' (length=6)
5 => string 'djsnaso' (length=7)
这应该适合您:
natcasesort($array);
这是一个数组自然忽略的情况
见: