How can I sort multidimensional array through key
<pre><code>Array
(
    [12] =&gt; Array
        (
            [id] =&gt; 12
            [name] =&gt; Car
            [children] =&gt; Array
                (
                    [0] =&gt; Array
                        (
                            [id] =&gt; 14
                            [name] =&gt; Volvo
                        )

                    [1] =&gt; Array
                        (
                            [id] =&gt; 15
                            [name] =&gt; Mercedes-Benz
                        )

                )

        )

    [13] =&gt; Array
        (
            [id] =&gt; 13
            [name] =&gt; Manga
            [children] =&gt; Array
                (
                    [0] =&gt; Array
                        (
                            [id] =&gt; 16
                            [name] =&gt; Naruto
                        )

                    [1] =&gt; Array
                        (
                            [id] =&gt; 17
                            [name] =&gt; Hunter X Hunter
                        )

                )

        )

    [18] =&gt; Array
        (
            [id] =&gt; 18
            [name] =&gt; aa
            [children] =&gt; Array
                (
                )

        )



)
</code></pre>

<p>Guys I want to sort the values of this array, i want to sort it by key and the key is 'name'. This should sort the first level and the second level thru key 'name'.</p>

<p>This array i put in <code>print_r()</code> so it looks like this. The array is not fix so i can add in the future.
<br/>
<br/></p>

<p>So after sorting the final value of the array is...</p>

<pre><code>Array
(

    [18] =&gt; Array
        (
            [id] =&gt; 18
            [name] =&gt; aa
            [children] =&gt; Array
                (
                )

        )

    [12] =&gt; Array
        (
            [id] =&gt; 12
            [name] =&gt; Car
            [children] =&gt; Array
                (
            [0] =&gt; Array
                        (
                            [id] =&gt; 15
                            [name] =&gt; Mercedes-Benz
                        )

                    [1] =&gt; Array
                        (
                            [id] =&gt; 14
                            [name] =&gt; Volvo
                        )

            )

        )

    [13] =&gt; Array
        (
            [id] =&gt; 13
            [name] =&gt; Manga
            [children] =&gt; Array
                (
            [0] =&gt; Array
                        (
                            [id] =&gt; 17
                            [name] =&gt; Hunter X Hunter
                        )

                    [1] =&gt; Array
                        (
                            [id] =&gt; 16
                            [name] =&gt; Naruto
                        )

                )

        )
)
</code></pre>

<p><br />
<br />
And this is the array in code.</p>

<pre><code>$categories = array(
                12 =&gt; 
                    array('id' =&gt;12, 
                              'name' =&gt; 'Car',
                                       'children' =&gt; 
                                        array(
                                            array('id' =&gt; 14,
                                                      'name' =&gt; 'volvo'
                                            )
                                        ),
                                        array(
                                            array('id' =&gt; 15,
                                                      'name' =&gt; 'Mercedez-Benz'
                                            )
                                        )
                            ),

                13 =&gt; 
                    array('id' =&gt;13, 
                              'name' =&gt; 'Manga',
                                       'children' =&gt; 
                                        array(
                                            array('id' =&gt; 16,
                                                      'name' =&gt; 'Naruto'
                                            )
                                        ),
                                        array(
                                            array('id' =&gt; 17,
                                                      'name' =&gt; 'Hunter X Hunter'
                                            )
                                        )
                            ),

                18=&gt;
                    array('id' =&gt; 18, 
                              'name'=&gt; 'aa', 
                                      'children' =&gt; array())


                );

echo "&lt;pre&gt;";

print_r($categories);
</code></pre>
