BlaBla.cn

PHP: uksort - Manual

BlaBla.cn
usort > <uasort
Last updated: Wed, 19 Mar 2008

uksort

(PHP 4, PHP 5)

uksort — 使用用户自定义的比较函数对数组中的键名进行排序

说明

bool uksort ( array &$array , callback $cmp_function )

本函数将使用用户提供的比较函数对数组中的键名进行排序。如果要排序的数组需要用一种不寻常的标准进行排序,那么应该使用此函数。

cmp_function 函数应接受两个参数,该参数将被 array 中的一对键名填充。比较函数在第一个参数小于,等于,或大于第二个参数时必须分别返回一个小于零,等于零,或大于零的整数。

如果成功则返回 TRUE ,失败则返回 FALSE

Example#1 uksort() 例子

<?php
function  cmp ( $a $b )
{
    if (
$a  ==  $b ) {
        return 
0 ;
    }
    return (
$a  $b ) ? - 1 ;
}

$a  = array( =>  "four" =>  "three" 20  =>  "twenty" 10  =>  "ten" );

uksort ( $a "cmp" );

foreach (
$a  as  $key  =>  $value ) {
    echo 
"$key: $value\n" ;
}
?>

上例将输出:

20: twenty
10: ten
4: four
3: three

      

参见 usort()uasort()sort()asort()arsort()ksort()natsort()rsort()



usort > <uasort
Last updated: Wed, 19 Mar 2008
 

 
BlaBla.cn

© 2005-2008 BlaBla.cn 版权所有