array sort by key value grepper code example
Example: array sort by key value grepper
$inventory = [
['name' => 'Loik', 'price' => 500],
['name' => 'Loik1', 'price' => 200],
['name' => 'Loik2', 'price' => 600],
['name' => 'Loik3', 'price' => 100],
];
$price = array_column($inventory, 'price');
array_multisort($price, SORT_DESC, $inventory);
print_r($inventory);
//Array (
[0] => Array ( [name] => Loik2 [price] => 600 )
[1] => Array ( [name] => Loik [price] => 500 )
[2] => Array ( [name] => Loik1 [price] => 200 )
[3] => Array ( [name] => Loik3 [price] => 100 )
)