Answers for "how to sort an array in php by specific key"

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
1

php sort array by specific key

usort($array, function ($a, $b) {
  return ($a['specific_key'] < $b['specific_key']) ? -1 : 1;
});
Posted by: Guest on January-22-2021
-1

php order array by specific key

function cmp($a, $b)
    {
        return strcmp($a->display_name, $b->display_name);
    }

    usort($blogusers, "cmp");

    foreach ($blogusers as $bloguser)
    {
        ...
Posted by: Guest on July-14-2020

Code answers related to "how to sort an array in php by specific key"

Browse Popular Code Answers by Language