Bug #53553 [Fbk->Opn]: Same value items reverted in asort() and arsort()
| From: | clau dot cristea at gmail dot com | Date: | Thu, 16 Dec 2010 12:26:51 +0000 |
| Subject: | Bug #53553 [Fbk->Opn]: Same value items reverted in asort() and arsort() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-157025@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=53553&edit=1
ID: 53553
User updated by: clau dot cristea at gmail dot com
Reported by: clau dot cristea at gmail dot com
Summary: Same value items reverted in asort() and arsort()
-Status: Feedback
+Status: Open
Type: Bug
Package: Arrays related
Operating System: Debian
PHP Version: 5.3.4
Block user comment: N
Private report: N
New Comment:
> Where is it stated in the docs the sort is stable?
Don't know... Where is stated that is not?
Previous Comments:
------------------------------------------------------------------------
[2010-12-16 11:52:27] cataphract@php.net
Where is it stated in the docs the sort is stable?
------------------------------------------------------------------------
[2010-12-16 11:10:39] clau dot cristea at gmail dot com
Description:
------------
After sorting an associative array with asort() or arsort() items having
same value are reverted.
Those sorting must preserve order on same value case.
---
From manual page: http://www.php.net/function.arsort
---
Test script:
---------------
<?php
$a = array('first' => 2, 'second' => 2);
$b = $a; // Save original.
print "Original:\n";
print_r($a);
asort($a);
print "\n\nasort():\n";
print_r($a);
arsort($b);
print "\n\narsort():\n";
print_r($b);
print "\n";
?>
Expected result:
----------------
I'm expecting that asort() and arsort() to preserve the order of items
having the same value.
Actual result:
--------------
See below asort(); and arsort(); that keys were reverted.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=53553&edit=1