php 数组函数

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

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

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

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

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

<?php
$fruits = [
    "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
*/

发表评论