Skip to content

Strange behavior of array_multisort #1474

Open
@Sekiphp

Description

@Sekiphp

Hello,

during investigation of PHP doc I found interesting thing in array_multisort function.

For argument rest there is written:

rest
More arrays, optionally followed by sort order and flags. Only elements corresponding to equivalent elements in previous arrays are compared. In other words, the sort is lexicographical.

Sort order and flags (in this direction), but in example 2 these parameters are switched. Switching should be allowed, but only if flags value is SORT_REGULAR, but is not this case

<?php
$ar = array(
       array("10", 11, 100, 100, "a"),
       array(   1,  2, "2",   3,   1)
      );
array_multisort($ar[0], SORT_ASC, SORT_STRING,
                $ar[1], SORT_NUMERIC, SORT_DESC);
var_dump($ar);
?>

EN DOC: https://www.php.net/manual/en/function.array-multisort.php
Code: https://github.com/php/php-src/blob/5d6bc25063e571da936010b1fae822f5d610deca/ext/standard/array.c#L5630

Live example: https://sandbox.onlinephpfunctions.com?s=s7EvyCjg5VJJLFKwVUgsKkqs1ODlUoAACFfJ0EBJR8HQEIgNDKCEUqKSpg6aOiADqEbBCChrBNSgoGAMIgw1Yco0rXm5wCrjc0tzSjKL84tKNIDWRhvE6igE-weFxDsGO0NZwSFBnn7uCAvgAKTeEKbeL9TXNcgTpsfFNdgZZEVZYlF8SmluAchsEN_eDgA%2C&v=7.3.5

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions