ID:               20982
 Comment by:       [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
 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] [EMAIL PROTECTED]

# 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

Reply via email to