Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

php sort array of array by key

$inventory = [
	['price' => 10.99, 'product' => 'foo 1'],
    ['price' => 5.99, 'product' => 'foo 2'],
  	['price' => 100, 'product' => 'foo 3'],
  
];

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

array_multisort($price, SORT_DESC, $inventory);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #php #sort #array #array #key
ADD COMMENT
Topic
Name
3+7 =