php sort multidimensional array

77

$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);
array_multisort(array_map(function($element) {
      return $element['order'];
  }, $array), SORT_ASC, $array);

print_r($array);
// PHP 7+
usort($arr, function ($a, $b) {
        return $a['key'] <=> $b['key'];
    });

Comments

Submit
0 Comments