1function sortByAge($a, $b) {
2 return $a['age'] > $b['age'];
3}
4$people=[
5 ["age"=>54,"first_name"=>"Bob","last_name"=>"Dillion"],
6 ["age"=>22,"first_name"=>"Sarah","last_name"=>"Harvard"],
7 ["age"=>31,"first_name"=>"Chuck","last_name"=>"Bartowski"]
8];
9
10usort($people, 'sortByAge'); //$people is now sorted by age (ascending)
1array_multisort(array_map(function($element) {
2 return $element['order'];
3 }, $array), SORT_ASC, $array);
4
5print_r($array);
1 $keys = array_column($array, 'Price');
2
3 array_multisort($keys, SORT_ASC, $array);
4
5 print_r($array);
1$inventory = array(
2 array("type"=>"Fruit", "price"=>3.50),
3 array("type"=>"milk", "price"=>2.90),
4 array("type"=>"Pork", "price"=>5.43),
5);
6
7$prices = array_column($inventory, 'price');
8$inventory_prices = array_multisort($prices, SORT_DESC, $inventory);
9
10$types = array_map(strtolower, array_column($inventory, 'type'));
11$inventory_types = array_multisort($types, SORT_ASC, $inventory);