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
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: 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: Sat May 18 17:01:33 2024 UTC