Php 정렬 배열

코드 예제

10
0

키별로 php 정렬 배열

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

배열 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
2
0

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);
2
0

정렬 다중 배열 php

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

		array_multisort($keys, SORT_ASC, $array);
	
		print_r($array);
1
0

배열 정렬 php


<?php

$fruits = array("lemon", "orange", "banana", "apple");
sort($fruits);
foreach ($fruits as $key => $val) {
    echo $val;
}
/*
OUTPUT:
apple
banana
lemon
orange
*/
?>

1
0

php 저장소 정렬 된 배열

$array = array();
$sorted_array = $array;
asort($sorted_array);
1
0

연관 배열 값으로 php 정렬

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

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................