title: PHP Sort a multidimensional array by number of items
body: <p>I have an array such as:</p>
  
  <pre><code>Array
  (
      [DEF] =&gt; Array
          (
              [0] =&gt; Array
                  (
                      [type] =&gt; 1
                      [id] =&gt; 1212
                      [name] =&gt; Jane Doe
                      [current] =&gt; 1
                  )
  
              [1] =&gt; Array
                  (
                      [type] =&gt; 1
                      [id] =&gt; 3123121
                      [name] =&gt; Door
                      [current] =&gt; 
                  )
          )
  
      [ABC] =&gt; Array
          (
              [0] =&gt; Array
                  (
                      [type] =&gt; 1
                      [id] =&gt; 1234
                      [name] =&gt; John Doe
                      [current] =&gt; 
                  )
          )
  
      [WW] =&gt; Array
          (
              [0] =&gt; Array
                  (
                      [type] =&gt; 1
                      [id] =&gt; 1212
                      [name] =&gt; Jane Doe
                      [current] =&gt; 1
                  )
  
              [1] =&gt; Array
                  (
                      [type] =&gt; 1
                      [id] =&gt; 3123121
                      [name] =&gt; Door
                      [current] =&gt; 
                  )
  
              [2] =&gt; Array
                  (
                      [type] =&gt; 1
                      [id] =&gt; 64646
                      [name] =&gt; Floor
                      [current] =&gt; 
                  )
          )
  )
  </code></pre>
  
  <p>And I want to sort this array by number ( count() ) of inner-array items descending (i.e. most items first), so I will have this array:</p>
  
  <pre><code>Array
  (
      [WW] =&gt; Array
          (
              [0] =&gt; Array
                  (
                      [type] =&gt; 1
                      [id] =&gt; 1212
                      [name] =&gt; Jane Doe
                      [current] =&gt; 1
                  )
  
              [1] =&gt; Array
                  (
                      [type] =&gt; 1
                      [id] =&gt; 3123121
                      [name] =&gt; Door
                      [current] =&gt; 
                  )
  
              [2] =&gt; Array
                  (
                      [type] =&gt; 1
                      [id] =&gt; 64646
                      [name] =&gt; Floor
                      [current] =&gt; 
                  )
          )
  
      [DEF] =&gt; Array
          (
              [0] =&gt; Array
                  (
                      [type] =&gt; 1
                      [id] =&gt; 1212
                      [name] =&gt; Jane Doe
                      [current] =&gt; 1
                  )
  
              [1] =&gt; Array
                  (
                      [type] =&gt; 1
                      [id] =&gt; 3123121
                      [name] =&gt; Door
                      [current] =&gt; 
                  )
          )
  
      [ABC] =&gt; Array
          (
              [0] =&gt; Array
                  (
                      [type] =&gt; 1
                      [id] =&gt; 1234
                      [name] =&gt; John Doe
                      [current] =&gt; 
                  )
          )
  )
  </code></pre>
  
  <p>Can anyone suggest an efficient way to do so? Thanks.</p>