Answers for "php sort 3 level array by key"

PHP
2

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

sort multidimensional array php by key

$people= array(
    array("age"=>54,"first_name"=>"bob","last_name"=>"Dillion"),
    array("age"=>22,"first_name"=>"darah","last_name"=>"Harvard"),
    array("age"=>31,"first_name"=>"ahuck","last_name"=>"Bartowski"),
);

echo '<PRE>';
print_r($people);


$keys = array_column($people, 'first_name');
print_r($keys);

array_multisort($keys, SORT_ASC, $people);

print_r($people);
Posted by: Guest on September-17-2021

Code answers related to "php sort 3 level array by key"

Browse Popular Code Answers by Language