php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1887 uksort() not working properly
Submitted: 1999-07-26 18:54 UTC Modified: 1999-07-27 12:18 UTC
From: bbray at xmission dot com Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 4.0 Beta 1 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: bbray at xmission dot com
New email:
PHP Version: OS:

 

 [1999-07-26 18:54 UTC] bbray at xmission dot com
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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-07-27 12:18 UTC] andrey at cvs dot php dot net
Fixed in CVS.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Jun 10 16:00:01 2026 UTC