title: Group PHP array elements based on single value in each array
body: <p>I currently have an array which looks like:</p>
  
  <pre><code>  Array
  (
      [0] =&gt; Array
          (
              [id] =&gt; 1
              [name] =&gt; Test 1
              [age] =&gt; 42
              [another_id] =&gt; 5
          )
  
      [1] =&gt; Array
          (
               [id] =&gt; 2
              [name] =&gt; Test 2
             [age] =&gt; 47
              [another_id] =&gt; 3
          )
  
      [2] =&gt; Array
          (
               [id] =&gt; 3
              [name] =&gt; Test 3
              [age] =&gt; 30
              [another_id] =&gt; 2
          )
     [3] =&gt; Array
          (
               [id] =&gt; 4
              [name] =&gt; Test 7
              [age] =&gt; 60
              [another_id] =&gt; 3
          )
     [4] =&gt; Array
          (
               [id] =&gt; 5
              [name] =&gt; Test 10
              [age] =&gt; 38
              [another_id] =&gt; 3
          )
  
  )
  </code></pre>
  
  <p>What I am looking to do is take all of the array items and print out a report of the items but group them by the 'another_id' field.
  For example the outcome I am looking for is:</p>
  
  <pre><code>REPORT
      **Another id (2)**
      Name: Test 3
  
      **Another id (3)** 
      Name: Test 2
      Name: Test 7
      Name: Test 10
  
      **Another id (5)** 
      Name: Test 1
  </code></pre>
  
  <p>I can group the items together but they all remain in a single array and I can't seem to separate them from each other to generate a report</p>
  
  <pre><code>  $grouped_types = array();
  
    foreach($invalid_results as $type){
        $grouped_types[$type['another_id']][] = $type;
    }
    print_r($grouped_types);
  </code></pre>
  
  <p>Can anyone help me? Much appreciated!</p>