Answers for "how to sort multidimensional array by case insensitive in php"

PHP
9

php sort multidimensional array

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)
Posted by: Guest on August-06-2019
2

php sort multidimensional array

array_multisort(array_map(function($element) {
      return $element['order'];
  }, $array), SORT_ASC, $array);

print_r($array);
Posted by: Guest on June-09-2020
1

php sort multidimensional array

$inventory = array(
   array("type"=>"Fruit", "price"=>3.50),
   array("type"=>"milk", "price"=>2.90),
   array("type"=>"Pork", "price"=>5.43),
);

$prices = array_column($inventory, 'price');
$inventory_prices = array_multisort($prices, SORT_DESC, $inventory);

$types = array_map(strtolower, array_column($inventory, 'type'));
$inventory_types = array_multisort($types, SORT_ASC, $inventory);
Posted by: Guest on September-04-2020

Code answers related to "how to sort multidimensional array by case insensitive in php"

Browse Popular Code Answers by Language