php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30912 array_multisort was broken
Submitted: 2004-11-26 15:44 UTC Modified: 2004-11-27 12:01 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: bolk at hitv dot ru Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.3.10RC1 OS: Linux RedHat
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: bolk at hitv dot ru
New email:
PHP Version: OS:

 

 [2004-11-26 15:44 UTC] bolk at hitv dot ru
Description:
------------
array_multisort was broken

Reproduce code:
---------------
	$rel2 = array(17, 100, 100, 100, 100, 100, 100, 100, 17, 17, 17, 17, 17);
	$rel  = array('a','b', 'c', 'd', 'e', 'f', 'g', 'h', 'x','y','z','xx','ww');

	array_multisort ($rel2, SORT_NUMERIC, SORT_DESC, $rel, SORT_REGULAR );

	print_r($rel2);


Expected result:
----------------
Array
(
    [0] => 100
    [1] => 100
    [2] => 100
    [3] => 100
    [4] => 100
    [5] => 100
    [6] => 100
    [7] => 17
    [8] => 17
    [9] => 17
    [10] => 17
    [11] => 17
    [12] => 17
)


Actual result:
--------------
Array
(
    [0] => 17
    [1] => 100
    [2] => 100
    [3] => 100
    [4] => 100
    [5] => 100
    [6] => 100
    [7] => 100
    [8] => 17
    [9] => 17
    [10] => 17
    [11] => 17
    [12] => 17
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-11-27 08:08 UTC] tony2001@php.net
That's how array_multisort() works.
"The first array is the primary one to sort by. The rows (values) in that array that compare the same are sorted by the next input array, and so on."
Take a look at examples in docs - they show pretty same behaviour and that's really expected.
 [2004-11-27 12:01 UTC] bolk at hitv dot ru
Hm... But in previos versions (for expample PHP 4.3.9) my example works fine. Thank for your help.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 12:01:32 2024 UTC