|
|
 |
krsort (PHP 3>= 3.0.13, PHP 4 , PHP 5) krsort -- 对数组按照键名逆向排序 说明int krsort ( array array [, int sort_flags])
对数组按照键名逆向排序,保留键名到数据的关联。主要用于结合数组。
例子 1. krsort() 例子 |
<?php
$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
krsort ($fruits);
reset ($fruits);
while (list ($key, $val) = each ($fruits)) {
echo "$key = $val\n";
}
?>
|
本例将显示:
d = lemon
c = apple
b = banana
a = orange |
|
可以用可选参数 sort_flags 改变排序的行为,详情见 sort()。
参见 asort(),arsort(),ksort(),sort(),natsort() 和 rsort()。
lolo at phpheaven dot net
29-Nov-2000 04:33
If you want to emulate the krsort function for an older version of php, you
can use this piece of code:
function KeyComp($a, $b)
{
return -(strcmp($a,$b));
}
function
krsort($MyArray)
{
uksort($MyArray,
"KeyComp");
}
Maybe obvious and useless, but who
knows...
| |