早睡早起,方能养生
Sleep early rise early, way to keep healthy

PHP二维数组排序

super
2021-05-31 15:54
views 2719

代码示例:

 

$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);

 

在线运行

 

运行结果



分享
0 条讨论
top