#19259 [Fbk->Csd]: usort() leaves array unsorted
ID: 19259
Updated by: sniper@php.net
Reported By: bug020905@stormkeepers.com
-Status: Feedback
+Status: Closed
Bug Type: Arrays related
Operating System: OSF1 V4.0 1229
PHP Version: 4.2.2
New Comment:
Closed then. Get the 4.2.3 when it's released..today/tomorrow iirc..
Previous Comments:
------------------------------------------------------------------------
[2002-09-06 05:30:07] nohn@php.net
Works fine with me with PHP 4.2.3RC2. Seems to be a duplicate of Bug
#17449.
------------------------------------------------------------------------
[2002-09-06 05:25:00] sniper@php.net
Please try using this CVS snapshot:
http://snaps.php.net/php4-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php4-win32-latest.zip
------------------------------------------------------------------------
[2002-09-05 18:44:59] bug020905@stormkeepers.com
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 this bug report at http://bugs.php.net/?id=19259&edit=1
Thread (6 messages)