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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
35 - 32 = ?
Subscribe to this entry?

 
 [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 16 02:01:33 2024 UTC