php sort multidimensional associative array by value code example
Example 1: php sort by associative array value
//php 7+
usort($inventory, function ($item1, $item2) {
return $item1['price'] <=> $item2['price'];
});
Example 2: php sort multidimensional array by value
function sortByOrder($a, $b) {
return $a['order'] - $b['order'];
}
usort($myArray, 'sortByOrder');