PHP rsort() 函数
PHP 教程
· 2019-01-22 22:29:15
实例
对数组 $cars 中的元素按字母进行降序排序:
<?php
$cars=array("Volvo","BMW","Toyota");
rsort($cars);
?>
$cars=array("Volvo","BMW","Toyota");
rsort($cars);
?>
定义和用法
rsort() 函数对数值数组进行降序排序。
提示:请使用 sort() 函数对数值数组进行升序排序。
语法
rsort(array,sortingtype);
| 参数 | 描述 |
|---|---|
| array | 必需。规定要进行排序的数组。 |
| sortingtype | 可选。规定如何排列数组的元素/项目。可能的值:
|
技术细节
| 返回值: | 如果成功则返回 TRUE,如果失败则返回 FALSE。 |
|---|---|
| PHP 版本: | 4+ |
更多实例
实例 1
对数组 $numbers 中的元素按数字进行降序排序:
<?php
$numbers=array(4,6,2,22,11);
rsort($numbers);
?>
$numbers=array(4,6,2,22,11);
rsort($numbers);
?>
实例 2
把每一项作为数字来处理,并对数组 $cars 中的元素进行降序排序:
<?php
$cars=array("Volvo","BMW","Toyota");
rsort($cars,SORT_NUMERIC);
?>
$cars=array("Volvo","BMW","Toyota");
rsort($cars,SORT_NUMERIC);
?>
点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html
Impractical Python Projects
Lee Vaughan / No Starch Press / 2018-11 / USD 29.95
Impractical Python Projects picks up where the complete beginner books leave off, expanding on existing concepts and introducing new tools that you’ll use every day. And to keep things interesting, ea......一起来看看 《Impractical Python Projects》 这本书的介绍吧!