php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54980 array_multisort uses second array to sort
Submitted: 2011-06-03 09:30 UTC Modified: 2015-05-08 21:56 UTC
Votes:8
Avg. Score:4.6 ± 0.7
Reproduced:8 of 8 (100.0%)
Same Version:5 (62.5%)
Same OS:4 (50.0%)
From: chx1975 at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: Arrays related
PHP Version: Irrelevant OS: Irrelevant
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: chx1975 at gmail dot com
New email:
PHP Version: OS:

 

 [2011-06-03 09:30 UTC] chx1975 at gmail dot com
Description:
------------
I thought array_multisort sorts the first array and orders the consequent arrays 
accordingly. Changing $sort['C'] to 3 indeed makes the error message go away so we think 
the error is only triggered if the sort does not happen in the first array. This is 
related to http://bugs.php.net/bug.php?id=54259 but I have simplified Brad's script as 
much as I can -- and he reported as a feature request. I think this is a bug. At least a 
documentation bug.

Test script:
---------------
$sort['A'] = 2;
$sort['B'] = 1;
$sort['C'] = 1;
$menu['A'] = 0; 
$menu['B'] = (object) array(0);
$menu['C'] = 0;
array_multisort($sort, SORT_NUMERIC, $menu);


Expected result:
----------------
No error message shown

Actual result:
--------------
PHP Notice:  Object of class stdClass could not be converted to int in 
/tmp/chx_array_multisort.txt on line 11


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-05-08 21:56 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2015-05-08 21:56 UTC] cmb@php.net
| I thought array_multisort sorts the first array and orders the
| consequent arrays accordingly.

That's only half the story. If there are identical values in the
first array, the respective elements of the second array are
compared to decide the order. See example #1, where this is
documented.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Aug 10 16:01:23 2020 UTC