📜  php 按子数组值排序数组 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:06.885000             🧑  作者: Mango

代码示例1
function sortByAge($a, $b) {
    return $a['age'] > $b['age'];
}
$people=[
    ["age"=>54,"first_name"=>"Bob","last_name"=>"Dillion"],
    ["age"=>22,"first_name"=>"Sarah","last_name"=>"Harvard"],
    ["age"=>31,"first_name"=>"Chuck","last_name"=>"Bartowski"]
];

usort($people, 'sortByAge'); //$people is now sorted by age (ascending)