Register now or log in to join your professional community.
<?php
$age= array("Peter"=>"", "Ben"=>"", "Joe"=>"");
arsort($age);
?>
Using usort + anonymous function
http://php.net/manual/en/function.usort.php
http://php.net/manual/en/functions.anonymous.php
You can do an ascending sort like this:
usort($inventory, function ($item1, $item2) {
return $item1['price'] <=> $item2['price'];
});
Or a descending sort like this:
usort($inventory, function ($item1, $item2) {
return $item2['price'] <=> $item1['price'];
});