(PHP 4, PHP 5)
arsort — 对数组进行逆向排序并保持索引关系
&$array
[, int $sort_flags
] )本函数对数组进行排序,数组的索引保持和单元的关联。主要用于对那些单元顺序很重要的结合数组进行排序。
成功时返回 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 被按照字母顺序逆向排序,并且单元的索引关系不变。
可以用可选的参数 sort_flags
改变排序的行为,详情见 sort()。
array
The input array.
sort_flags
You may modify the behavior of the sort using the optional parameter
sort_flags
, for details see
sort().
成功时返回 TRUE
, 或者在失败时返回 FALSE
.
Example #2 arsort() example
<?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
The fruits have been sorted in reverse alphabetical order, and the index associated with each element has been maintained.