如何按给定键的值对关联数组进行排序并在php中维护键? [重复]

This question already has an answer here:

Given this array

$inventory = array(
    "sdfsdfsdsx65fsdf1"=>array("type"=>"fruit", "price"=>3.50),
    "sdfsdfsdsx65fsdf2"=>array("type"=>"milk", "price"=>2.90),
    "sdfsdfsdsx65fsdf3"=>array("type"=>"pork", "price"=>5.43)
);

I want output like below

$inventory = array(
    "sdfsdfsdsx65fsdf3"=>array("type"=>"pork", "price"=>5.43),
    "sdfsdfsdsx65fsdf1"=>array("type"=>"fruit", "price"=>3.50),
    "sdfsdfsdsx65fsdf2"=>array("type"=>"milk", "price"=>2.90)  
);
</div>
$inventory = array(
  array("sdfsdfsdsx65fsdf1"=>array("type"=>"fruit", "price"=>3.50)),
  array("sdfsdfsdsx65fsdf2"=>array("type"=>"milk", "price"=>2.90)),
  array("sdfsdfsdsx65fsdf3"=>array("type"=>"pork", "price"=>5.43))
);

usort($inventory, function($a, $b) {
  foreach ($a as $a);
  foreach ($b as $b);
  if ($a['price'] == $b['price']) return 0;
  return ($a['price'] < $b['price']) ? 1 : -1;
});

print_r($inventory);