d.alex
0
Q:

php array sort by key value

  $weight = [
    'Pete' => 75, 
    'Benjamin' => 89,
    'Jonathan' => 101
  ];  	
  ksort($weight);
5
To PHP sort array by key, you should use: 
	ksort() (for ascending order) or krsort() (for descending order). 
      
To PHP sort array by value, you will need functions:
	asort() and arsort() (for ascending and descending orders).
1
$price = array_column($inventory, 'price');

array_multisort($price, SORT_DESC, $inventory);
0

New to Communities?

Join the community