“PHP mengurutkan array berdasarkan nilai” Kode Jawaban

PHP mengurutkan array dengan kunci

  $weight = [
    'Pete' => 75, 
    'Benjamin' => 89,
    'Jonathan' => 101
  ];  	
  ksort($weight);
Xenophobic Xenomorph

PHP Sorts berdasarkan nilai array asosiatif

//php 7+
usort($inventory, function ($item1, $item2) {
    return $item1['price'] <=> $item2['price'];
});
Friendly Hawk

PHP Array Sorts berdasarkan Nilai Kunci

To PHP sort array by key, you should use: 
	ksort() (for ascending order) or krsort() (for descending order). 
      
To PHP sort array by value, you will need functions:
	asort() and arsort() (for ascending and descending orders).
Envious Eagle

Urutkan array php

<?php
$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");
asort($fruits);
foreach ($fruits as $key => $val) {
    echo "$key = $val\n";
}
?>
//Would output:
c = apple
b = banana
d = lemon
a = orange  
GelatinousMustard

Array Pesanan PHP

<?php
$array = array("id" => 8, "id" =>1, "id" =>3, "id"=>2, "id" => 12, "id" =>19);
print_r($array->orderBy("id"));
?>
Light Loris

PHP mengurutkan array berdasarkan nilai

$price = array();
foreach ($inventory as $key => $row)
{
    $price[$key] = $row['price'];
}
array_multisort($price, SORT_DESC, $inventory);
Silly Sardine

Jawaban yang mirip dengan “PHP mengurutkan array berdasarkan nilai”

Pertanyaan yang mirip dengan “PHP mengurutkan array berdasarkan nilai”

Lebih banyak jawaban terkait untuk “PHP mengurutkan array berdasarkan nilai” di PHP

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya