How array_multisort() works?

I don’t really understand the way array_multisort function works.

Here is the code which I am using from php doc.


$ar = [
    [
        "10", 11, 100, 123, 'a'
    ],
        [
            1, 2, "2", 3, 1
        ]

];

$result = array_multisort($ar[0],SORT_ASC,SORT_STRING,
                          $ar[1],SORT_NUMERIC, SORT_DESC);

echo '<pre>';
print_r($ar);
echo '</pre>';

Output:

[0] => Array
        (
            [0] => 10
            [1] => 100
            [2] => 11
            [3] => 123
            [4] => a
        )

    [1] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 2
            [3] => 3
            [4] => 1
        )

But doc has different output??

the first array will transform to “10”, 100, 100, 11, “a” (it was sorted as strings in ascending order). The second will contain 1, 3, “2”, 2, 1

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.