php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #6353 array_multisort() flags should be bit-or-ed, not seperated by comma
Submitted: 2000-08-25 09:32 UTC Modified: 2000-08-31 09:31 UTC
From: ccjeagle at ms6 dot hinet dot net Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.0.1pl2 OS: FreeBSD4.1
Private report: No CVE-ID: None
 [2000-08-25 09:32 UTC] ccjeagle at ms6 dot hinet dot net
Seems that array_multisort() flags should be bit-or-ed, not seperated by comma.

i.e. array_multisort($arr1,SORT_DESC|SORT_NUMERIC,
     $arr2,SORT_ASC|SORT_STRING),

NOT array_multisort($arr1,SORT_DESC,SORT_NUMERIC,
     $arr2, SORT_ASC,SORT_STRING)
As document said.

<?php
$array1 = array(1,7,5,5,5) ;
$array2 = array(9,7,6,'b','a') ;
array_multisort($array1,SORT_DESC,SORT_REGULAR,
                       $array2,SORT_NUMERIC,SORT_DESC) ;
// Got a warning that parameter 3 should be an array 
array_multisort($array1,SORT_DESC|SORT_REGULAR,
                       $array2,SORT_NUMERIC|SORT_DESC) ;
// That's OK
?>

I think the proto should be :
bool array_multisort (array ar1 [, mixed arg ] [, array ...])

Regards,
CCJ

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-08-25 09:40 UTC] andrei@php.net
This example works just fine for me with latest CVS. Could you try that?
 [2000-08-25 10:19 UTC] ccjeagle at ms6 dot hinet dot net
Sorry, I don't have a CVS version yet.
I use 4.0.1pl2.
Does that mean the newer release would work fine ?
 [2000-08-31 09:18 UTC] jmoore@php.net
In pl2 this is correct only

array_multisort($array1,SORT_DESC|SORT_REGULAR,
                       $array2,SORT_NUMERIC|SORT_DESC) ;

works.

In 4.0.2 onwards both of these appear to work.

array_multisort($array1,SORT_DESC,SORT_REGULAR,
                       $array2,SORT_NUMERIC,SORT_DESC) ; 
array_multisort($array1,SORT_DESC|SORT_REGULAR,
                       $array2,SORT_NUMERIC|SORT_DESC) ;


Do you guys think we should add a note to the manual about this behaviour?
 [2000-08-31 09:31 UTC] jmoore@php.net
This does not occur in 4.0.2, the manual is correct in stating 

array_multisort($array1,SORT_DESC,SORT_REGULAR,        $array2,SORT_NUMERIC,SORT_DESC) ; 

Is the correct way of calling this function. Apperently the other just works by chance.

Closing
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Mon Jun 15 22:00:02 2026 UTC