#19259 [NEW]: usort() leaves array unsorted

From: Date: Thu, 05 Sep 2002 23:44:59 +0000
Subject: #19259 [NEW]: usort() leaves array unsorted
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-18551@lists.php.net to get a copy of this message
From: bug020905@stormkeepers.com Operating system: OSF1 V4.0 1229 PHP version: 4.2.2 PHP Bug Type: Arrays related Bug description: usort() leaves array unsorted usort() does not seem to be actually sorting the array. The user-defined sort function is being called, but no matter what the function does, the array remains in its original order. The "Example 1" cut-and-pasted from the usort() function documentation page: function cmp ($a, $b) { if ($a == $b) return 0; return ($a > $b) ? -1 : 1; } $a = array (3, 2, 5, 6, 1); usort ($a, "cmp"); while (list ($key, $value) = each ($a)) { echo "$key: $value\n"; } Produces the following output: 0: 3 1: 2 2: 5 3: 6 4: 1 (Should have returned the values in descending order, as on the usort() documentation page.) The other examples do not work on this platform, either; they always leave the array unmodified. Configuration line reported by phpinfo(): './configure' '--with-apache=../apache_1.3.26' '--with-gd=/ usr/local' '--with-png-dir=/usr/local' '--with-jpeg-dir=/ usr/local' '--with-zlib-dir=/usr/local' '--with-xml' '-- with-dom=/usr/local' '--with-dom-xslt=/usr/local' '--with- dom-exslt=/usr/local' '--with-mysql' '--with-mm' '--enable- discard-path' '--prefix=/usr/local/apache-1.3.26' '-- enable-memory-limit=yes' '--enable-debug=no' '--enable- safe-mode' -- Edit bug report at http://bugs.php.net/?id=19259&edit=1 -- Try a CVS snapshot: http://bugs.php.net/fix.php?id=19259&r=trysnapshot Fixed in CVS: http://bugs.php.net/fix.php?id=19259&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=19259&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=19259&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=19259&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=19259&r=support Expected behavior: http://bugs.php.net/fix.php?id=19259&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=19259&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=19259&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=19259&r=globals

« previous php.bugs (#18551) next »