PHP usort() 函数
PHP 教程
· 2019-01-23 05:59:19
实例
使用用户自定义的比较函数对数组 $a 中的元素进行排序:Sort the elements of the $a array using a user-defined comparison function:
<?php
function my_sort($a,$b)
{
if ($a==$b) return 0;
return ($a<$b)?-1:1;
}
$a=array(4,2,8,6);
usort($a,"my_sort");
?>
function my_sort($a,$b)
{
if ($a==$b) return 0;
return ($a<$b)?-1:1;
}
$a=array(4,2,8,6);
usort($a,"my_sort");
?>
定义和用法
usort() 使用用户自定义的比较函数对数组进行排序。
语法
usort(array,myfunction);
| 参数 | 描述 |
|---|---|
| array | 必需。规定要排序的数组。 |
| myfunction | 可选。一个定义了可调用比较函数的字符串。如果第一个参数 <, =, > 第二个参数,相应地比较函数必须返回一个 <, =, > 0 的整数。 |
技术细节
| 返回值: | 如果成功则返回 TRUE,如果失败则返回 FALSE。 |
|---|---|
| PHP 版本: | 4+ |
点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html
Web Design Handbook
Baeck, Philippe de 编 / 2009-12 / $ 22.54
This non-technical book brings together contemporary web design's latest and most original creative examples in the areas of services, media, blogs, contacts, links and jobs. It also traces the latest......一起来看看 《Web Design Handbook》 这本书的介绍吧!