按最低到最高排序数组

时间:2014-03-10 20:40:47

标签: php arrays sorting

我有这个数组需要重新排序“TH Thickness”从最低到最高。不知道我怎么能做到这一点。

有什么想法吗?

[thickness] => Array
    (
        [0] => Array
            (
                [TH Thickness ID] => 23
                [TH Thickness] => 100
            )

        [1] => Array
            (
                [TH Thickness ID] => 24
                [TH Thickness] => 120
            )

        [2] => Array
            (
                [TH Thickness ID] => 33
                [TH Thickness] => 150
            )

        [3] => Array
            (
                [TH Thickness ID] => 25
                [TH Thickness] => 50
            )

        [4] => Array
            (
                [TH Thickness ID] => 21
                [TH Thickness] => 60
            )

        [5] => Array
            (
                [TH Thickness ID] => 26
                [TH Thickness] => 70
            )

        [6] => Array
            (
                [TH Thickness ID] => 22
                [TH Thickness] => 80
            )

    )

1 个答案:

答案 0 :(得分:1)

PHP> = 5.5.0

array_multisort(array_column($array['thickness'], 'TH Thickness'), SORT_ASC, $array['thickness']);

PHP< 5.5.0 - 您可以查看问题的可能重复项,或者:

foreach($array['thickness'] as $k => $v) {
   $sort[$k] = $v['TH Thickness'];
}
array_multisort($sort, SORT_ASC, $array['thickness']);