(PHP 4, PHP 5, PHP 7)
uasort — 使锟斤拷锟矫伙拷锟皆讹拷锟斤拷谋冉虾锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷械锟街碉拷锟斤拷锟斤拷锟斤拷虿⒈锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟�
锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟津并憋拷锟斤拷锟斤拷锟斤拷锟酵碉拷元之锟斤拷墓锟斤拷锟斤拷锟�
锟斤拷要锟斤拷锟节讹拷锟斤拷些锟斤拷元顺锟斤拷锟斤拷锟揭拷慕锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷颉1冉虾锟斤拷锟斤拷锟斤拷没锟斤拷远锟斤拷锟侥★拷
Note:
If two members compare as equal, their relative order in the sorted array is undefined.
锟缴癸拷时锟斤拷锟斤拷 TRUE
锟斤拷 锟斤拷锟斤拷锟斤拷失锟斤拷时锟斤拷锟斤拷 FALSE
锟斤拷
Example #1 uasort() 锟侥伙拷锟斤拷锟斤拷锟斤拷
<?php
// Comparison function
function cmp($a, $b) {
if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
}
// Array to be sorted
$array = array('a' => 4, 'b' => 8, 'c' => -1, 'd' => -9, 'e' => 2, 'f' => 5, 'g' => 3, 'h' => -4);
print_r($array);
// Sort and print the resulting array
uasort($array, 'cmp');
print_r($array);
?>
锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�
Array ( [a] => 4 [b] => 8 [c] => -1 [d] => -9 [e] => 2 [f] => 5 [g] => 3 [h] => -4 ) Array ( [d] => -9 [h] => -4 [c] => -1 [e] => 2 [g] => 3 [a] => 4 [f] => 5 [b] => 8 )