PHP Sort a Multidimensional Array with asort

sort - sort an array and maintain index association

PHP asort function sorts a multidimensional array by the length of the array then by the first key

$array1 = array(array('x', 'y', 'z'), array('a', 'b', 'c'));

$array2 = array(array('x', 'y'), array('a', 'b', 'c'));

asort($array1);

asort($array2);

print_r($array1);

print_r($array2);

Results in:

Array
(
    [1] => Array
        (
            [0] => a
            [1] => b
            [2] => c
        )

    [0] => Array
        (
            [0] => x
            [1] => y
            [2] => z
        )

)
Array
(
    [0] => Array
        (
            [0] => x
            [1] => y
        )

    [1] => Array
        (
            [0] => a
            [1] => b
            [2] => c
        )

)