php 二维数组排序
<?php $arr = [ [ 'id' => 4, 'name' => 'si', ], [ 'id' => 1, 'name' => 'yi', ], [ 'id' => 2, 'name' => 'er', ], [ 'id' => 5, 'name' => 'wu', ], [ 'id' => 3, 'name' => 'san', ], ]; $sort_column = array_column($arr, 'id'); array_multisort($sort_column, SORT_DESC, $arr); echo '<pre>'; print_r($arr); die;
结果:
Array ( [0] => Array ( [id] => 5 [name] => wu ) [1] => Array ( [id] => 4 [name] => si ) [2] => Array ( [id] => 3 [name] => san ) [3] => Array ( [id] => 2 [name] => er ) [4] => Array ( [id] => 1 [name] => yi ) )
1