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
Learn Python 3 the Hard Way
Zed A. Shaw / Addison / 2017-7-7 / USD 30.74
You Will Learn Python 3! Zed Shaw has perfected the world’s best system for learning Python 3. Follow it and you will succeed—just like the millions of beginners Zed has taught to date! You bring t......一起来看看 《Learn Python 3 the Hard Way》 这本书的介绍吧!
随机密码生成器
多种字符组合密码
XML、JSON 在线转换
在线XML、JSON转换工具