对数组 $cars 中的元素按字母进行降序排序:
<?php
$cars=array("Maserati","BMW","Toyota",NULL);
rsort($cars,NULL);
?>
rsort() 函数对数值数组进行降序排序。
rsort(array,sortingtype,NULL);
参数 | 描述 |
---|---|
array | 必需。规定要进行排序的数组。 |
sortingtype |
可选。规定如何比较数组的元素/项目。可能的值:
|
rsort() 函数对数组的元素按照键值进行逆向排序。与 arsort() 的功能基本相同。
如果成功则返回 TRUE,否则返回 FALSE。
可选的第二个参数包含另外的排序标志。
返回值: | TRUE on success. FALSE on failure |
PHP 版本: | 4+ |
对数组 $numbers 中的元素按数字进行降序排序:
<?php
$numbers=array(4,6,2,22,11,NULL);
rsort($numbers,NULL);
?>
把项目作为数字来比较,并对数组 $cars 中的元素进行降序排序:
<?php
$cars=array("Maserati","BMW","Toyota",NULL);
rsort($cars,SORT_NUMERIC,NULL);
?>
©2020 IT自习室京ICP备20010815号