Answers for "php sort array by keyasc"

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 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

Browse Popular Code Answers by Language