问题
So I am trying to sort a list of folders and files and display them alphabetical the problem appears that if someone created a folder that starts with a captial letter that folder appears first for example if I had the following folders
Array
(
[0] => .
[1] => ..
[2] => _base
[3] => template
[4] => Website
)
I would expect when using scandir (scandir($directory, SCANDIR_SORT_ASCENDING)
) to see the folders listed out as above but instead that get listed out as
Array
(
[0] => .
[1] => ..
[2] => Website
[3] => _base
[4] => template
)
How would I be able to get this list sorted the correct way so that it wouldn't be case sensitive.
回答1:
This should work for you:
natcasesort($array);
It sort's an array natural ignore case
See: http://php.net/manual/en/function.natcasesort.php
回答2:
Maybe You should just use sort() function?
Example:
$x = array('.', '..', '22331', 'djsnaso', 'Aijndod', 'Wwwwww');
sort($x);
var_dump($x);
Return value:
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)
来源:https://stackoverflow.com/questions/27173295/scnadir-sort-order-asc-put-uppercase-letters-first