Answers for "php sort associative array by specific value"

PHP
2

php sort array by specific key

usort($array, function ($a, $b) {
  return ($a['specific_key'] < $b['specific_key']) ? -1 : 1;
});
Posted by: Guest on January-22-2021
4

php sort by associative array value

//php 7+
usort($inventory, function ($item1, $item2) {
    return $item1['price'] <=> $item2['price'];
});
Posted by: Guest on February-02-2021
0

php sort associative array by specific value

$price = array_column($inventory, 'price');

array_multisort($price, SORT_DESC, $inventory);
Posted by: Guest on May-04-2022

Code answers related to "php sort associative array by specific value"

Browse Popular Code Answers by Language