how to sort an integer array 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 sort array by value length
function sortByLength($a,$b){
return strlen($b)-strlen($a);
}
usort($array,'sortByLength');