php 数组函数

【rsort】排序数组(反向排序,返回值不保留原键名)

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

sort 函数的唯一区别是:排序的方向不同。

第二个参数效果完全等同于 sort,请参考

https://qianjinyike.com/【sort】排序数组(不再保留键名)

<?php
$fruits = [
    "d" => "lemon",
    "a" => "orange",
    "b" => "banana",
    "c" => "apple",
];
rsort($fruits);

foreach ($fruits as $key => $val) {
    echo "$key = $val\n";
}

/*
0 = orange
1 = lemon
2 = banana
3 = apple
*/

发表评论