|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2011-04-20 01:32 UTC] dtajchreber@php.net
-Status: Open
+Status: Bogus
[2011-04-20 01:32 UTC] dtajchreber@php.net
[2011-04-20 01:56 UTC] danvarin at googlemail dot com
[2011-04-20 01:59 UTC] mightyuhu@php.net
-Type: Bug
+Type: Feature/Change Request
[2011-04-20 01:59 UTC] mightyuhu@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Sat Mar 21 05:00:01 2026 UTC |
Description: ------------ In the manual it sais: "This function sorts an array such that array indices maintain their correlation with the array elements they are associated with." But when we have the same value the order of the keys is swapped. (See Test Script). This is unexpected and kind of destroys the correlation. In computer science terms one would say asort is not a stable sorting function. Tested with: - PHP 5.3.3-7+squeeze1 with Suhosin-Patch - PHP 5.3.6 - PHP 5.3.5 - PHP 5.2.17 Test script: --------------- <?php $testarray = array ('1' => (int) 23, '2' => (int) 1, '4' => (int) 1); var_dump($testarray); asort($testarray); var_dump($testarray); //4 and 2 are switched ?> Expected result: ---------------- array(3) { [1]=> int(23) [2]=> int(1) [4]=> int(1) } array(3) { [2]=> int(1) [4]=> int(1) [1]=> int(23) } Actual result: -------------- array(3) { [1]=> int(23) [2]=> int(1) [4]=> int(1) } array(3) { [4]=> int(1) [2]=> int(1) [1]=> int(23) }