Bug #18299 Updated: arsort works different on PHP 4.1.2 and PHP 4.2.0
| From: | hholzgra@php.net | Date: | Fri, 12 Jul 2002 09:47:07 +0000 |
| Subject: | Bug #18299 Updated: arsort works different on PHP 4.1.2 and PHP 4.2.0 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-13942@lists.php.net to get a copy of this message | ||
ID: 18299
Updated by: hholzgra@php.net
Reported By: glimpse@glimpse.fr.fm
-Status: Open
+Status: Bogus
Bug Type: Feature/Change Request
Operating System: Linux RedHat 6.2
PHP Version: 4.2.0
New Comment:
because we use a more efficient sort algorithm now
the result is different here, but still correct,
your array elements are perefectly sorted before
and after the asort() calls
whenever two elements are equal the sort algorithm
has the freedom to chose which to put first ...
Previous Comments:
------------------------------------------------------------------------
[2002-07-12 05:19:10] glimpse@glimpse.fr.fm
It seems like the arsort() function sort associative array strangely.
The same script does not give the same result:
$fruits =
array("d"=>"test","a"=>"test","b"=>"test","c"=>"test");
arsort ($fruits);
for (reset ($fruits); $key = key ($fruits); next ($fruits)) {
echo "fruits[$key] = ".$fruits[$key]."\n";
}
Result with PHP 4.1.2 :
fruits[d] = test fruits[a] = test fruits[b] = test fruits[c] = test
(with this order : d, a, b, c)
Result with PHP 4.2.0 :
fruits[c] = test fruits[b] = test fruits[a] = test fruits[d] = test
(with this order : c, b, a, d)
Why does the arsort() function change the order of the elements when
they have the same value in PHP 4.2.0 while not in PHP 4.1.2?
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=18299&edit=1