키별로 php 정렬 배열
$weight = [
'Pete' => 75,
'Benjamin' => 89,
'Jonathan' => 101
];
ksort($weight);
배열 php 의 정렬 배열
sort() //sort arrays in ascending order
rsort() //sort arrays in descending order
asort() //sort associative arrays in ascending order, according to the value
ksort() //sort associative arrays in ascending order, according to the key
arsort() //sort associative arrays in descending order, according to the value
krsort() //sort associative arrays in descending order, according to the key
//Example
$array = array(1, 3, 2);
sort($array) //1, 2, 3
php 는 키별로 배열 배열 정렬
$inventory = [
['price' => 10.99, 'product' => 'foo 1'],
['price' => 5.99, 'product' => 'foo 2'],
['price' => 100, 'product' => 'foo 3'],
];
$price = array_column($inventory, 'price');
array_multisort($price, SORT_DESC, $inventory);
정렬 다중 배열 php
$keys = array_column($array, 'Price');
array_multisort($keys, SORT_ASC, $array);
print_r($array);
배열 정렬 php
<?php
$fruits = array("lemon", "orange", "banana", "apple");
sort($fruits);
foreach ($fruits as $key => $val) {
echo $val;
}
/*
OUTPUT:
apple
banana
lemon
orange
*/
?>
php 저장소 정렬 된 배열
$array = array();
$sorted_array = $array;
asort($sorted_array);
연관 배열 값으로 php 정렬
//php 7+
usort($inventory, function ($item1, $item2) {
return $item1['price'] <=> $item2['price'];
});