I'm using array_multisort for sorting a multi-dimensional array but the final result does not keep the same keys for level 1. All the keys are numeric and i don't know if this could cause this issue. Here's the structure of the array:

[23] => Array
        (
            [107] => Array
                (
                    [1] => 1

after array_multisort it becomes like this:

[0] => Array
        (
            [107] => Array
                (
                    [1] => 1

    As the manual notes on the [man]array_multisort[/man] page:

    Associative ( string ) keys will be maintained, but numeric keys will be re-indexed.

    Use [man]array_keys[/man] to get an array of keys, and sort that along with the rest. Then [man]array_combine[/man] them back together.

      so i should include the $keys array in the array_multisort() and then use array_combine() with the $keys and the output of the array_multisort()? I've tried it but is not working...

        Write a Reply...