PHP二维数组排序


“PHP二维数组排序” 的解决办法:

代码示例:

 

$array = [
    [
        'name' => 'super1',
        'age' => 12
    ],
    [
        'name' => 'super2',
        'age' => 10
    ],
    [
        'name' => 'super3',
        'age' => 14
    ]
];


foreach ($array as $key => $row) {
    $distance[$key] = $row['age'];
}
array_multisort($distance, SORT_DESC, $array); // SORT_ASC 按照上升顺序排序, SORT_DESC 按照下降顺序排序。

print_r($array);

 

在线运行

 

运行结果