Answers for "order array in array by key value php"

PHP
1

sort array by key value in php

$inventory = array(

   array("type"=>"fruit", "price"=>3.50),
   array("type"=>"milk", "price"=>2.90),
   array("type"=>"pork", "price"=>5.43),

);
$price = array_column($inventory, 'price');
array_multisort($price, SORT_DESC, $inventory);
Posted by: Guest on June-03-2021
2

php array sort by key value

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).
Posted by: Guest on October-23-2020

Code answers related to "order array in array by key value php"

Browse Popular Code Answers by Language