Bug #18299 Updated: arsort works different on PHP 4.1.2 and PHP 4.2.0

From: Date: Fri, 12 Jul 2002 09:59:08 +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-13949@lists.php.net to get a copy of this message
ID: 18299 Updated by: glimpse@glimpse.fr.fm Reported By: glimpse@glimpse.fr.fm Status: Bogus Bug Type: Feature/Change Request Operating System: Linux RedHat 6.2 PHP Version: 4.2.0 New Comment: Ok, thanks. But I have some code based on that. I want my array not to be sorted when the values are the same. Where is the advantage to change the order in that case? I think this sort of changes will affect a very large pool of web applications already installed with PHP 4.1.x and using this function... This kind of changes seems not to be important, but it is! Best regards, Fred Previous Comments: ------------------------------------------------------------------------ [2002-07-12 05:47:07] hholzgra@php.net 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 ... ------------------------------------------------------------------------ [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

« previous php.bugs (#13949) next »