Note that there are some explanatory texts on larger screens.

plurals
  1. POSorting multidimensional array on each level separately
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/12900539/how-to-sort-the-following-php-multidimensional-array">How to sort the following PHP multidimensional array?</a> </p> </blockquote> <p>Let's say I have following array:</p> <pre><code>Array ( [0] =&gt; Array ( [id] =&gt; 5 [name] =&gt; Education [parent] =&gt; 1 [sort_order] =&gt; 3 [leaf] =&gt; 1 ) [1] =&gt; Array ( [id] =&gt; 6 [name] =&gt; Computers [parent] =&gt; 1 [sort_order] =&gt; 1 [leaf] =&gt; 1 ) [2] =&gt; Array ( [id] =&gt; 7 [name] =&gt; Science [parent] =&gt; 1 [sort_order] =&gt; 2 [children] =&gt; Array ( [0] =&gt; Array ( [id] =&gt; 8 [name] =&gt; Mathematics [parent] =&gt; 7 [sort_order] =&gt; 2 [children] =&gt; Array ( [0] =&gt; Array ( [id] =&gt; 11 [name] =&gt; Geometry [parent] =&gt; 8 [sort_order] =&gt; 2 [leaf] =&gt; 1 ) [1] =&gt; Array ( [id] =&gt; 12 [name] =&gt; Algebra [parent] =&gt; 8 [sort_order] =&gt; 1 [leaf] =&gt; 1 ) ) ) [1] =&gt; Array ( [id] =&gt; 9 [name] =&gt; Physics [parent] =&gt; 7 [sort_order] =&gt; 1 [leaf] =&gt; 1 ) [2] =&gt; Array ( [id] =&gt; 10 [name] =&gt; Biology [parent] =&gt; 7 [sort_order] =&gt; 4 [leaf] =&gt; 1 ) [3] =&gt; Array ( [id] =&gt; 13 [name] =&gt; History [parent] =&gt; 7 [sort_order] =&gt; 3 [leaf] =&gt; 1 ) ) ) </code></pre> <p>Is there any PHP built-in function which will sort this array separately on each level by <code>'sort_order'</code> value? I have found several sollutions, but all of them sorted alphabetically or have used ksort().</p> <p>There will be recursion needed probably, but I need some help how to start that. TIA.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload