Answers for "array sort by key value grepper"

0

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 ) 
)
Posted by: Guest on February-15-2021

Code answers related to "array sort by key value grepper"

Browse Popular Code Answers by Language