Group ROWS in array with same Identifier
<p>How can I run this array below inside of a <code>foreach</code> loop and group the rows together that share the same <code>section_id</code>?</p>

<p>I've labeled all the rows and sections with comment blocks.</p>

<p><strong>This is the array</strong></p>

<pre><code>Array ( 
    [0] =&gt; Array ( // Row 1
        [assessment_selection_id] =&gt; 63 
        [assessment_id] =&gt; 32 
        [section_id] =&gt; 1 // Section 1
        [question_id] =&gt; 1 
        [selection] =&gt; 2 
        [timestamp] =&gt; 1368160586 
   ) 
   [1] =&gt; Array ( // Row 2
        [assessment_selection_id] =&gt; 61 
        [assessment_id] =&gt; 32 
        [section_id] =&gt; 2 // Section 2
        [question_id] =&gt; 1 
        [selection] =&gt; 3 
        [timestamp] =&gt; 1368160510 
   )
   [2] =&gt; Array ( // Row 3
        [assessment_selection_id] =&gt; 61 
        [assessment_id] =&gt; 32 
        [section_id] =&gt; 2 // Section 2
        [question_id] =&gt; 1 
        [selection] =&gt; 3 
        [timestamp] =&gt; 1368160510 
   ) 

   [3] =&gt; Array ( // Row 4
        [assessment_selection_id] =&gt; 61 
        [assessment_id] =&gt; 32 
        [section_id] =&gt; 2 // Section 2
        [question_id] =&gt; 1 
        [selection] =&gt; 3 
        [timestamp] =&gt; 1368160510 
   ) 
)
</code></pre>

<p><br /></p>

<p><strong>Expected result</strong></p>

<pre><code>Array ( 
   [0] =&gt; Array ( // Section 1
        [0] =&gt; Array ( // Row 1 
            [assessment_selection_id] =&gt; 63 
            [assessment_id] =&gt; 32 
            [section_id] =&gt; 1 
            [question_id] =&gt; 1 
            [selection] =&gt; 2 
            [timestamp] =&gt; 1368160586 
        )
    )
    [1] =&gt; Array ( // Section 2
        [0] =&gt; Array ( // Row 1
            [assessment_selection_id] =&gt; 61 
            [assessment_id] =&gt; 32 
            [section_id] =&gt; 2 
            [question_id] =&gt; 1 
            [selection] =&gt; 2 
            [timestamp] =&gt; 1368160586 
        )
       [1] =&gt; Array ( // Row 2
            [assessment_selection_id] =&gt; 61 
            [assessment_id] =&gt; 32 
            [section_id] =&gt; 2 
            [question_id] =&gt; 1 
            [selection] =&gt; 2 
            [timestamp] =&gt; 1368160586 
        )
       [2] =&gt; Array ( // Row 3
            [assessment_selection_id] =&gt; 61 
            [assessment_id] =&gt; 32 
            [section_id] =&gt; 2 
            [question_id] =&gt; 1 
            [selection] =&gt; 2 
            [timestamp] =&gt; 1368160586 
        )
    )
)
</code></pre>

<p><br /></p>

<p><strong>Expected result without array</strong></p>

<p><strong>Section 1</strong></p>

<ul>
<li><p><strong>Row 1</strong></p>

<p>assessment_selection_id, 
assessment_id, 
section_id, 
question_id, 
selection, 
timestamp</p></li>
</ul>

<p><strong>Section 2</strong></p>

<ul>
<li><p><strong>Row 1</strong></p>

<p>assessment_selection_id, 
assessment_id, 
section_id, 
question_id, 
selection, 
timestamp</p></li>
<li><p><strong>Row 2</strong></p>

<p>assessment_selection_id, 
assessment_id, 
section_id, 
question_id, 
selection, 
timestamp</p></li>
<li><p><strong>Row 3</strong></p>

<p>assessment_selection_id, 
assessment_id, 
section_id, 
question_id, 
selection, 
timestamp</p></li>
</ul>
