实例使用用户自定义的比较函数对数组 $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"); ?> 定义和用法usort() 使用用户自定义的比较函数对数组进行排序。 语法usort(array,myfunction);
参数 | 描述 |
---|
array | 必需。规定要排序的数组。 | myfunction | 可选。一个定义了可调用比较函数的字符串。如果第一个参数 <, =, > 第二个参数,相应地比较函数必须返回一个 <, =, > 0 的整数。 |
技术细节返回值: | 如果成功则返回 TRUE,如果失败则返回 FALSE。 |
---|
PHP 版本: | 4+ |
---|
下载地址: PHP uksort() 函数 PHP cal_days_in_month() 函数 |