(PHP 4, PHP 5, PHP 7)
arsort — 对数组进行逆向排序并保持索引关系
&$array
[, int $sort_flags
= SORT_REGULAR
] )本函数对数组进行排序,数组的索引保持和单元的关联。
主要用于对那些单元顺序很重要的结合数组进行排序。
Note:
If two members compare as equal, their relative order in the sorted array is undefined.
成功时返回 TRUE
, 或者在失败时返回 FALSE
。
Example #1 arsort() 例子
<?php
$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");
arsort($fruits);
foreach ($fruits as $key => $val) {
echo "$key = $val\n";
}
?>
以上例程会输出:
a = orange d = lemon b = banana c = apple
fruits 被按照字母顺序逆向排序,并且单元的索引关系不变。