1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | $arr =[
array (
'name' => '小壞龍' ,
'age' =>28
),
array (
'name' => '小壞龍2' ,
'age' =>14
),
array (
'name' => '小壞龍3' ,
'age' =>59
),
array (
'name' => '小壞龍4' ,
'age' =>23
),
array (
'name' => '小壞龍5' ,
'age' =>23
),
array (
'name' => '小壞龍6' ,
'age' =>21
),
];
array_multisort (array_column( $arr , 'age' ),SORT_DESC, $arr );
print_r( $arr );
|
其中 array_column(數(shù)組,數(shù)組中的某個(gè)鍵值) 從多維數(shù)組中取出某個(gè)鍵值的一列 返回一個(gè)一維數(shù)組;
array_multisort(數(shù)組(一維數(shù)組),排序方式(SOTR_ASC,SOTR_DESC),其他數(shù)組(可以是二維的))
|