title: How to group a multidimensional array by a particular subarray value?
body: <p>I have a multidimensional array and am trying to group them according to the value in a specific column. </p>
  
  <p>I'm trying to group them by <code>level</code>, but I won't actually know the level beforehand.  So, it's not like I can put it in a <code>for</code> loop and say <code>while $i &lt; 7</code>, because I won't know that <code>7</code> is the maximum value for the level key, and frankly, I'm not sure that's how I would need to do it even if I did...   </p>
  
  <pre><code>Array (
     [0] =&gt; Array (
            [cust] =&gt; XT8900
            [type] =&gt; standard
            [level] =&gt; 1
            )
     [1] =&gt; Array (
            [cust] =&gt; XT8944
            [type] =&gt; standard
            [level] =&gt; 1
            )
     [2] =&gt; Array (
            [cust] =&gt; XT8922
            [type] =&gt; premier
            [level] =&gt; 3
            )
     [3] =&gt; Array (
            [cust] =&gt; XT8816
            [type] =&gt; permier
            [level] =&gt; 3
            )
     [4] =&gt; Array (
            [cust] =&gt; XT7434
            [type] =&gt; standard
            [level] =&gt; 7
            )
  )
  </code></pre>
  
  <p>What I'm hoping to produce:</p>
  
  <pre><code>Array (
  
     [1] =&gt; Array (
            [0] =&gt; Array (
                      [cust] =&gt; XT8900
                      [type] =&gt; standard
                      )
            [1] =&gt; Array (
                      [cust] =&gt; XT8944
                      [type] =&gt; standard
                      )
            )
  
     [3] =&gt; Array (
            [2] =&gt; Array (
                   [cust] =&gt; XT8922
                   [type] =&gt; premier
                   )
  
            [3] =&gt; Array (
                   [cust] =&gt; XT8816
                   [type] =&gt; permier
                   )
            )
  
     [7] =&gt; Array (
            [4] =&gt; Array (
                   [cust] =&gt; XT7434
                   [type] =&gt; standard
                   )
            )
  )
  </code></pre>