📅  最后修改于: 2022-03-11 14:54:47.886000             🧑  作者: Mango
$users=array(
array("sex"=>0,"age"=>9),
array("sex"=>0,"age"=>34),
array("sex"=>1,"age"=>17),
array("sex"=>0,"age"=>1),
array("sex"=>1,"age"=>3)
);
//sort first by sex, then by age
usort($users, function($a,$b){
return ($a['sex'] == $b['sex']) ?
$a['age'] < $b['age'] :
$a['sex'] < $b['sex'];
});