超越PHP PHP动态 | 经典文章 | CLASS | 相关下载 | 常见问题 | FORUM | WIKI | 在线手册
Site search:    
<uasortusort>
Last updated: Fri, 22 Jun 2007

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()




add a note add a note User Contributed Notes
uksort
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

<uasortusort>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22