#20982 [Opn->Csd]: sort doesn't sort
| From: | sniper@php.net | Date: | Fri, 13 Dec 2002 08:25:28 +0000 |
| Subject: | #20982 [Opn->Csd]: sort doesn't sort | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-27565@lists.php.net to get a copy of this message | ||
ID: 20982
Updated by: sniper@php.net
Reported By: tom@minnesota.com
-Status: Open
+Status: Closed
Bug Type: Arrays related
Operating System: NetBSD/Alpha (64bit) - 1.6
PHP Version: 4.2.2
New Comment:
This bug has been fixed in CVS.
In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2002-12-13 00:37:26] tom@minnesota.com
I also tried other various sort functions and they all failed to sort:
# cat sort.php
<?php
// sort() demo
echo "\n";
$fruits = array ("lemon", "orange", "banana", "apple");
sort ($fruits);
reset ($fruits);
while (list ($key, $val) = each ($fruits)) {
echo "fruits[".$key."] = ".$val."\n";
}
// asort() demo
echo "\n";
$fruits = array ("d"=>"lemon", "a"=>"orange",
"b"=>"banana",
"c"=>"apple");
asort ($fruits);
reset ($fruits);
while (list ($key, $val) = each ($fruits)) {
echo "$key = $val\n";
}
// ksort() demo
echo "\n";
$fruits = array ("d"=>"lemon", "a"=>"orange",
"b"=>"banana",
"c"=>"apple");
ksort ($fruits);
reset ($fruits);
while (list ($key, $val) = each ($fruits)) {
echo "$key = $val\n";
}
// usort() demo
echo "\n";
$fruits = array();
function cmp ($a, $b) {
return strcmp($a["fruit"], $b["fruit"]);
}
$fruits[0]["fruit"] = "lemons";
$fruits[1]["fruit"] = "apples";
$fruits[2]["fruit"] = "grapes";
usort($fruits, "cmp");
while (list ($key, $value) = each ($fruits)) {
echo "\$fruits[$key]: " . $value["fruit"] . "\n";
}
?>
# php -q sort.php
fruits[0] = lemon
fruits[1] = orange
fruits[2] = banana
fruits[3] = apple
d = lemon
a = orange
b = banana
c = apple
d = lemon
a = orange
b = banana
c = apple
$fruits[0]: lemons
$fruits[1]: apples
$fruits[2]: grapes
#
------------------------------------------------------------------------
[2002-12-13 00:09:11] tom@minnesota.com
# cat sort.php
<?php
$fruits = array ("lemon", "orange", "banana", "apple");
sort ($fruits);
reset ($fruits);
while (list ($key, $val) = each ($fruits)) {
echo "fruits[".$key."] = ".$val."\n";
}
?>
# php -v
4.2.2
# php -q sort.php
fruits[0] = lemon
fruits[1] = orange
fruits[2] = banana
fruits[3] = apple
#
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=20982&edit=1