php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6195 array_multisort accepts only one SORT_REGULAR|SORT_NUMERIC|SORT_STRING flag
Submitted: 2000-08-16 09:39 UTC Modified: 2000-08-16 09:52 UTC
From: alex at zend dot com Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 4.0.1pl2 OS: all
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: alex at zend dot com
New email:
PHP Version: OS:

 

 [2000-08-16 09:39 UTC] alex at zend dot com
<?php 
        $dict = array(
                                        "alpha",        "bravo",        "charlie",      "delta",
                                        "echo",         "foxtrot",      "golf",         "hotel",
                                        "yankee",       "zulu"
                                 );
        srand((double)microtime() * 1000000);

        $p = generate_str_array(100);
        $q = range(0, 99);
        shuffle($p);
        shuffle($q);
        array_multisort($p, SORT_DESC, SORT_STRING, $q, SORT_ASC, SORT_NUMERIC);

// !!!!! the second arrays is not sorted

        print_array($p);
        print_array($q);

        function print_array(&$arr)
        {
                foreach ($arr as $i => $j)
                        print("$i: $j\n");
        }

        function generate_str_array($elements)
        {
                global $dict;

                for ($i = 0; $i < $elements; $i++)
                        $arr[$i] = $dict[$i % sizeof($dict)];
                return $arr;
        }

?>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-08-16 09:52 UTC] andrei@php.net
That's how array_multisort() works. The second array will not
be sorted if all the entries in the first array are unique. Only those
entries corresponding to duplicate entries in the first array will be
sorted. Think of the SQL "order by" behavior when used on multiple
columns.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 00:01:30 2024 UTC