php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53553 Same value items reverted in asort() and arsort()
Submitted: 2010-12-16 11:10 UTC Modified: 2010-12-16 14:17 UTC
From: clau dot cristea at gmail dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.3.4 OS: Debian
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: clau dot cristea at gmail dot com
New email:
PHP Version: OS:

 

 [2010-12-16 11:10 UTC] 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-16 11:52 UTC] cataphract@php.net
-Status: Open +Status: Feedback
 [2010-12-16 11:52 UTC] cataphract@php.net
Where is it stated in the docs the sort is stable?
 [2010-12-16 13:26 UTC] clau dot cristea at gmail dot com
-Status: Feedback +Status: Open
 [2010-12-16 13:26 UTC] clau dot cristea at gmail dot com
> Where is it stated in the docs the sort is stable?

Don't know... Where is stated that is not?
 [2010-12-16 14:17 UTC] cataphract@php.net
-Status: Open +Status: Bogus
 [2010-12-16 14:17 UTC] cataphract@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

Then I don't know where you got the idea the sorting of asort() and arsort() was stable.

Closing as bogus. See also bug #53341.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 17:01:29 2024 UTC