根据值在数组内部排列数组

时间:2018-03-17 10:35:47

标签: php

我有一个数组数组,如下面的数组长度将是未知的我想根据每个数组中的第三个元素按升序对数组进行排序。

Array
(
    [0] => Array
        (
            [0] => 30
            [1] => AbdulA
            [2] => TEST White Truck 7 am 9:30 am 12 pm 2:30 pm
            [3] => 8
            [4] => 12
        )

    [1] => Array
        (
            [0] => 31
            [1] => AbdulAnn
            [2] => TEST White Truck 7 am 9:30 am 12 pm 2:30 pm
            [3] => 2
            [4] => 8
        )

    [2] => Array
        (
            [0] => 32
            [1] => pacha
            [2] => TEST RED TRUCK
            [3] => 0
            [4] => 1
        )

)

1 个答案:

答案 0 :(得分:0)

您可以使用usort

function cmp($a, $b) {
    return $a[3] - $b[3];
}
usort($array, "cmp");