“Urutkan PHP array multidimensi berdasarkan kunci” 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

$inventory = array(
   array("type"=>"Fruit", "price"=>3.50),
   array("type"=>"milk", "price"=>2.90),
   array("type"=>"Pork", "price"=>5.43),
);

$prices = array_column($inventory, 'price');
$inventory_prices = array_multisort($prices, SORT_DESC, $inventory);

$types = array_map(strtolower, array_column($inventory, 'type'));
$inventory_types = array_multisort($types, SORT_ASC, $inventory);
ArtesanoMultimedia

array multidimensi sortir php

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

print_r($array);
Thoughtless Turkey

Urutkan Multi Array PHP

		$keys = array_column($array, 'Price');

		array_multisort($keys, SORT_ASC, $array);
	
		print_r($array);
Zany Zebra

Urutkan PHP array multidimensi berdasarkan kunci

$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);
Poised Porpoise

PHP Urutkan Array Multidimensi berdasarkan Nilai

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

Jawaban yang mirip dengan “Urutkan PHP array multidimensi berdasarkan kunci”

Pertanyaan yang mirip dengan “Urutkan PHP array multidimensi berdasarkan kunci”

Lebih banyak jawaban terkait untuk “Urutkan PHP array multidimensi berdasarkan kunci” di PHP

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya