“PHP Sort Multi Dimensional Array” Kode Jawaban

array multidimensi sortir php

function sortByAge($a, $b) {
    return $a['age'] > $b['age'];
}
$people=[
    ["age"=>54,"first_name"=>"Bob","last_name"=>"Dillion"],
    ["age"=>22,"first_name"=>"Sarah","last_name"=>"Harvard"],
    ["age"=>31,"first_name"=>"Chuck","last_name"=>"Bartowski"]
];

usort($people, 'sortByAge'); //$people is now sorted by age (ascending)
Grepper

array multidimensi sortir php

array_multisort(array_map(function($element) {
      return $element['order'];
  }, $array), SORT_ASC, $array);

print_r($array);
Thoughtless Turkey

PHP Sort Multi Dimensional Array

usort($myArray, function($a, $b) {
    return $a['order'] <=> $b['order'];
});
RapTToR

Jawaban yang mirip dengan “PHP Sort Multi Dimensional Array”

Pertanyaan yang mirip dengan “PHP Sort Multi Dimensional Array”

Lebih banyak jawaban terkait untuk “PHP Sort Multi Dimensional Array” di PHP

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya