title: Array grouping in PHP
body: <p>I have an array in PHP:</p>
  
  <pre><code>array (size=xxx)
    0 =&gt; 
      array (size=9)
        'cat' =&gt; string 'FIRST CAT'
        'dur' =&gt; string '10'
        'type' =&gt; string 'Type description 10'
        'start' =&gt; string '00:00'
        'end' =&gt; string '01:00'
        'desc' =&gt; string 'Event description 10-1'
        'price' =&gt; string 'xxx'
        'extra' =&gt; string 'yyy'
    1 =&gt; 
      array (size=9)
        'cat' =&gt; string ''
        'dur' =&gt; string ''
        'type' =&gt; string ''
        'start' =&gt; string '01:00'
        'end' =&gt; string '02:00'
        'desc' =&gt; string 'Event description 10-2'
        'price' =&gt; string ''
        'extra' =&gt; string ''
    2 =&gt; 
      array (size=9)
        'cat' =&gt; string ''
        'dur' =&gt; string ''
        'type' =&gt; string ''
        'start' =&gt; string '02:00'
        'end' =&gt; string '03:00'
        'desc' =&gt; string 'Event description 10-3'
        'price' =&gt; string ''
        'extra' =&gt; string ''
    3 =&gt; 
      array (size=9)
        'cat' =&gt; string ''
        'dur' =&gt; string '20'
        'type' =&gt; string 'Type description 20'
        'start' =&gt; string '00:00'
        'end' =&gt; string '01:00'
        'desc' =&gt; string 'Event description 20-1'
        'price' =&gt; string 'xxx'
        'extra' =&gt; string 'yyy'
    4 =&gt; 
      array (size=9)
        'cat' =&gt; string ''
        'dur' =&gt; string ''
        'type' =&gt; string ''
        'start' =&gt; string '01:00'
        'end' =&gt; string '02:00'
        'desc' =&gt; string 'Event description 20-2'
        'price' =&gt; string ''
        'extra' =&gt; string ''
    5 =&gt; 
      array (size=9)
        'cat' =&gt; string ''
        'dur' =&gt; string ''
        'type' =&gt; string 'Type description 21'
        'start' =&gt; string '00:00'
        'end' =&gt; string '01:00'
        'desc' =&gt; string 'Event description 21-1'
        'price' =&gt; string 'xxx'
        'extra' =&gt; string 'yyy'
    6 =&gt; 
      array (size=9)
        'cat' =&gt; string ''
        'dur' =&gt; string ''
        'type' =&gt; string ''
        'start' =&gt; string '01:00'
        'end' =&gt; string '02:00'
        'desc' =&gt; string 'Event description 21-2'
        'price' =&gt; string ''
        'extra' =&gt; string ''
    7 =&gt; 
      array (size=9)
        'cat' =&gt; string 'SECOND CAT'
        'dur' =&gt; string '10'
        'type' =&gt; string 'Type description 100'
        'start' =&gt; string '00:00'
        'end' =&gt; string '01:00'
        'desc' =&gt; string 'Event description 100-1'
        'price' =&gt; string 'xxx'
        'extra' =&gt; string 'yyy'
    8 =&gt; 
      array (size=9)
        'cat' =&gt; string ''
        'dur' =&gt; string ''
        'type' =&gt; string ''
        'start' =&gt; string '01:00'
        'end' =&gt; string '02:00'
        'desc' =&gt; string 'Event description 100-2'
        'price' =&gt; string ''
        'extra' =&gt; string ''
    9 =&gt; 
      array (size=9)
        'cat' =&gt; string ''
        'dur' =&gt; string '20'
        'type' =&gt; string 'Type description 200'
        'start' =&gt; string '00:00'
        'end' =&gt; string '01:00'
        'desc' =&gt; string 'Event description 200-1'
        'price' =&gt; string 'xxx'
        'extra' =&gt; string 'yyy'
    10 =&gt; 
      array (size=9)
        'cat' =&gt; string ''
        'dur' =&gt; string ''
        'type' =&gt; string ''
        'start' =&gt; string '01:00'
        'end' =&gt; string '02:00'
        'desc' =&gt; string 'Event description 200-2'
        'price' =&gt; string ''
        'extra' =&gt; string ''
    11 =&gt; 
      array (size=9)
        'cat' =&gt; string ''
        'dur' =&gt; string ''
        'type' =&gt; string 'Type description 210'
        'start' =&gt; string '00:00'
        'end' =&gt; string '01:00'
        'desc' =&gt; string 'Event description 210-1'
        'price' =&gt; string 'xxx'
        'extra' =&gt; string 'yyy'
    etc...
  </code></pre>
  
  <p>I need to group this array first by <code>cat</code>, then by <code>dur</code>, then <code>type</code>. This <code>type</code> array would have two strings - <code>price</code> and <code>extra</code> and another array which would consist of all the events data - <code>start</code>, <code>end</code> and <code>desc</code>. Final array outline (based on example above) should look like this:</p>
  
  <pre><code>'FIRST CAT'                                           // 'cat'
      '10'                                              // 'dur'
        'Type description 10', 'xxx', 'yyy'             // 'type', 'price', 'extra'
            (array of events)
            '00:00', '01:00', 'Event description 10-1'  // 'start', 'end', 'desc'
            '01:00', '02:00', 'Event description 10-2'  // 'start', 'end', 'desc'
            '02:00', '03:00', 'Event description 10-3'  // 'start', 'end', 'desc'
      '20'
        'Type description 20', 'xxx', 'yyy'
            (array of events)
            '00:00', '01:00', 'Event description 20-1'
            '01:00', '02:00', 'Event description 20-2'
        'Type description 21', 'xxx', 'yyy'
            (array of events)
            '00:00', '01:00', 'Event description 21-1'
            '01:00', '02:00', 'Event description 21-2'
  'SECOND CAT'
      '10'
        'Type description 100', 'xxx', 'yyy'
            (array of events)
            '00:00', '01:00', 'Event description 100-1'
            '01:00', '02:00', 'Event description 100-2'
      '20'
        'Type description 200', 'xxx', 'yyy'
            (array of events)
            '00:00', '01:00', 'Event description 200-1'
            '01:00', '02:00', 'Event description 200-2'
        'Type description 210', 'xxx', 'yyy'
            (array of events)
            '00:00', '01:00', 'Event description 210-1'
            '01:00', '02:00', 'Event description 210-2'
  </code></pre>
  
  <p>What would be the simplest way to convert my existing array to the one I need in the end?</p>