|
|
 |
uksort (PHP 3>= 3.0.4, PHP 4 , PHP 5) uksort --
使用用户自定义的比较函数对数组中的键名进行排序
说明void uksort ( array array, callback cmp_function)
本函数将使用用户提供的比较函数对数组中的键名进行排序。如果要排序的数组需要用一种不寻常的标准进行排序,那么应该使用此函数。
例子 1. uksort() 例子 |
<?php
function cmp ($a, $b) {
if ($a == $b) return 0;
return ($a > $b) ? -1 : 1;
}
$a = array (4 => "four", 3 => "three", 20 => "twenty", 10 => "ten");
uksort ($a, "cmp");
while (list ($key, $value) = each ($a)) {
echo "$key: $value\n";
}
?>
|
本例将显示:
20: twenty
10: ten
4: four
3: three |
|
参见
usort(),uasort(),sort(),asort(),arsort(),ksort(),natsort()
和 rsort()。
kumar at chicagomodular (dot) com
30-Jan-2003 01:12
The comparison function must return an integer less than, equal to, or
greater than zero if the first argument is considered to be respectively
less than, equal to, or greater than the second. --necessary info from
http://www.php.net/manual/en/function.usort.php
if you didn't see it already
| |