#20982 [Com]: sort doesn't sort
| From: | tom at minnesota dot com | Date: | Fri, 13 Dec 2002 06:37:26 +0000 |
| Subject: | #20982 [Com]: sort doesn't sort | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-27562@lists.php.net to get a copy of this message | ||
ID: 20982
Comment by: tom@minnesota.com
Reported By: tom@minnesota.com
Status: Open
Bug Type: Arrays related
Operating System: NetBSD/Alpha (64bit) - 1.6
PHP Version: 4.2.2
New Comment:
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
#
Previous Comments:
------------------------------------------------------------------------
[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