IT/php

php arsort 배열 첨자 기준 정렬 배열정렬

조원태 2016. 10. 6. 14:27
반응형

php arsort  배열 첨자 기준 정렬 배열정렬

arsort


(PHP 4, PHP 5, PHP 7)

arsort — Sort an array in reverse order and maintain index association


Description ¶


bool arsort ( array &$array [, int $sort_flags = SORT_REGULAR ] )

This function sorts an array such that array indices maintain their correlation with the array elements they are associated with.


This is used mainly when sorting associative arrays where the actual element order is significant.


Note:

If two members compare as equal, their relative order in the sorted array is undefined.

Parameters ¶


array

The input array.


sort_flags

You may modify the behavior of the sort using the optional parameter sort_flags, for details see sort().


Return Values ¶


Returns TRUE on success or FALSE on failure.


Examples ¶


Example #1 arsort() example


<?php

$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");

arsort($fruits);

foreach ($fruits as $key => $val) {

    echo "$key = $val\n";

}

?>

The above example will output:


a = orange

d = lemon

b = banana

c = apple

반응형

'IT > php' 카테고리의 다른 글

php array_sum 배열의 값 합 구하기  (0) 2016.10.06
php array_unique php 배열 중복값 제거 하기  (0) 2016.10.06
php array_map 배열 첨자 합치기  (0) 2016.10.06
array_slice 배열자르기  (0) 2016.10.06
php header charset uft-8  (0) 2016.02.14