Source Code:
(back to article)
<?php $inventory = [ [ 'type' => 'pork', 'price' => 5.43 ], ['type' => 'milk', 'price' => 2.9 ], ['type' => 'fruit', 'price' => 3.5] ]; function invenDescSort($item1, $item2) { if ($item1['price'] == $item2['price']) { return 0; } return $item1['price'] < $item2['price'] ? 1 : -1; } usort($inventory, 'invenDescSort'); var_dump($inventory); ?>
Result:
Report an issue