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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
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: Sun Apr 28 06:01:30 2024 UTC