如何对不区分大小写的数组进行排序?

时间:2014-02-05 06:31:33

标签: php

输入数组:

 Array
    (
        [6] => Array
            (
                [name] => Ashsish
            )

        [11] => Array
            (
                [name] => Nishu
            )

        [5] => Array
            (
                [name] => Pooja
            )

        [0] => Array
            (
                [name] => ankur
            )

        [2] => Array
            (
                [name] => boby
            )

        [9] => Array
            (
                [name] => chintu
            )

        [4] => Array
            (
                [name] => darshan
            )

        [8] => Array
            (
                [name] => honey
            )

        [10] => Array
            (
                [name] => jay
            )

        [3] => Array
            (
                [name] => pravin
            )

        [7] => Array
            (
                [name] => sagar
            )

        [1] => Array
            (
                [name] => zalak
            )

    )

3 个答案:

答案 0 :(得分:0)

<强> natcasesort

(PHP 4,PHP 5)

natcasesort - 使用不区分大小写的“自然顺序”算法对数组进行排序 说明

 bool natcasesort ( array &$array )

了解更多 http://www.php.net/manual/en/function.natcasesort.php

答案 1 :(得分:0)

使用sort

sort($input_array, SORT_NATURAL | SORT_FLAG_CASE)

请注意,SORT_NATURALSORT_FLAG_CASE使用 PHP 5.4.0 + 。有关详细信息,请参阅sort manual

答案 2 :(得分:0)

使用uasort()strcasecmp()进行比较:

uasort($list, function($a, $b) {
    return strcasecmp($a['name'], $b['name']);
});