★ wanayoo — archive 1999 http://www.php.net/manual/ja/function.uksort.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to Arrays
Quick Reference
English version of this pageGerman version of this pageItalian version of this pageFrench version of this pageHungarian version of this page
Arrays
* array
* array_count_values
* array_diff
* array_flip
* array_intersect
* array_keys
* array_merge
* array_merge_recursive
* array_multisort
* array_pad
* array_pop
* array_push
* array_rand
* array_reverse
* array_shift
* array_slice
* array_splice
* array_unshift
* array_values
* array_walk
* arsort
* asort
* compact
* count
* current
* each
* end
* extract
* in_array
* key
* krsort
* ksort
* list
* next
* pos
* prev
* range
* reset
* rsort
* shuffle
* sizeof
* sort
* uasort
* uksort
* usort
Manual: uksort
View the source code for this pageSearch the site



Previous page
 uasort
 Updated
Sat, 12 Aug 2000
usort 
Next page


uksort

(PHP3 >= 3.0.4, PHP4 )

uksort --  ユーザー定義の比較関数を用いてキーで配列をソートします

説明

void uksort (array array, function cmp_function)

この関数は、ユーザー定義の比較関数を用いて配列のキーをソートします。 ソートしたい配列を複雑な基準でソートする必要がある場合には、 この関数を使う必要があります。

例 1. uksort()の例


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(), rsort() も参照下さい。


User Contributed Notes: uksort


antosch@gmx.de
20-Feb-2000 08:21
this example filters double numbers, that means if u have two times 30, it just displays it one time in the result. any clues how this is prevented?


Jesse@bend.com
26-Jul-2000 05:02
Filters double numbers you say?
Assuming you mean an array like <?=array( 1 => "one", 2 => "two", 1 => "one")?> loses the redundant keys, I have to say that I was under the impression that assosciative arrays required unique keys to begin with. Otherwise are you trying to say that you have non-unique keys that are getting lost?



 About Notes


Previous page
 uasort
 Updated
Sat, 12 Aug 2000
usort 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.