title: PHP - Recursive sort arrays by value
body: <p>I have a big array like:</p>
  
  <pre><code>Array
  (
      [1] =&gt; Array
          (
              [ID] =&gt; 1
              [name] =&gt; Product 1
              [productorder] =&gt; 7
              [children] =&gt; Array
                  (
                      [1] =&gt; Array
                          (
                              [ID] =&gt; 54
                              [name] =&gt; Product 1.1
                              [productorder] =&gt; 4
                          )
  
                      [2] =&gt; Array
                          (
                              [ID] =&gt; 8
                              [name] =&gt; Product 1.2
                              [productorder] =&gt; 2
                          )
                  )
          )
      [2] =&gt; Array
          (
              [ID] =&gt; 2
              [name] =&gt; Product 2
              [productorder] =&gt; 1
          )
      [3] =&gt; Array
          (
              [ID] =&gt; 3
              [name] =&gt; Product 3
              [productorder] =&gt; 5
          )
  )
  </code></pre>
  
  <p>I need to reorder all the arrays position by the value <code>productorder</code>.
  It must be recursive via the "children" key, but some of the arrays could not have this key.
  I tried <a href="https://stackoverflow.com/a/2699159/12078509">from this topic</a>:</p>
  
  <pre><code>usort($myArray, function($a, $b) {
      return $a['order'] - $b['order'];
  });
  </code></pre>
  
  <p>but it's not recursive! Any idea?</p>