Search code examples
phparray-multisort

array_multisort not working properly?


I'm using array_multisort like always, but this time it does have trouble sorting correctly.

I use it to sort a multidimensional array ($data), but I simplified the problem in this example:

    $data = array(6 => 'WEEK 48', 7 => 'WEEK 49', 8 => 'WEEK 47', 9 => 'WEEK 50', 10 => 'WEEK 51');

    $sort = array(8 => 201647, 6 => 201648, 7 => 201649, 9 => 201650, 10 => 201651);

    array_multisort($sort, SORT_ASC, $data);

    Output:
    Array
    (
        [0] => WEEK 48
        [1] => WEEK 49
        [2] => WEEK 47
        [3] => WEEK 50
        [4] => WEEK 51
    )

What am I missing?


Solution

  • Stupid me, there was a ksort($data) in between lines which screwed up the sorting.