PHP 4.0 Bug #1887: uksort() not working properly
| From: | bbray at xmission dot com | Date: | Mon, 26 Jul 1999 22:54:13 +0000 |
| Subject: | PHP 4.0 Bug #1887: uksort() not working properly | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-9203@lists.php.net to get a copy of this message | ||
From: bbray@xmission.com
Operating system: Linux
PHP version: 4.0 Beta 1
PHP Bug Type: Misbehaving function
Bug description: uksort() not working properly
run the following script on php3 and php4:
<?
function reverse_key_sort($a, $b) {
if ($a == $b) return 0;
return ($a > $b) ? -1 : 1;
}
$a = array(1 => 'orange', 2 => 'apple', 3 => 'bananna');
uksort($a, reverse_key_sort);
reset($a);
while ( list($key, $val) = each($a) ) {
echo "KEY=$key VAL=$val<BR>";
}
?>
The output looks like this for php3:
KEY=3 VAL=bananna
KEY=2 VAL=apple
KEY=1 VAL=orange
And like this for php4:
KEY=1 VAL=orange
KEY=2 VAL=apple
KEY=3 VAL=bananna
Also, the only reason that I have use the uksort function is because php3 lacks a
rksort() function (even though it has a ksort() function) It seems like it shouldnt be to
difficult to add the rksort() function? (Cut and paste the ksort() and reverse the sorting?)
Thanks,
Brian Bray