We need to sort the array by
price
value
$inventory = array(
array("type"=>"fruit", "price"=>3.50),
array("type"=>"milk", "price"=>2.90),
array("type"=>"pork", "price"=>5.43),
);
The solution is to use
array_multisort
function
$price = array();
foreach ($inventory as $key => $row)
{
$price[$key] = $row['price'];
}
array_multisort($price, SORT_DESC, $inventory);
In PHP 5.5 or later
array_column
function can be used
$price = array_column($inventory, 'price');
array_multisort($price, SORT_DESC, $inventory);