sort an array by a value php 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 array sort
// Fonction de comparaison
function cmp($a, $b) {
if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
}