Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php scnadir排序顺序asc将大写字母放在第一位_Php_Sorting_Scandir - Fatal编程技术网

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);
这是一个数组自然忽略的情况

见: