php merging arrays
<p>In the multidimensional array below, I would like to merge arrays that have the same merge_id. I'm not sure "merge" is the right word: in the example below, array['0'] should become array['0'] with in it array['0']['0'] and array['0']['1'], the latter being equal to array['1']. I hope this makes sense ...</p>

<p>The array comes out of the db sorted on merge_id so arrays with matching merge_id are always "next to" each other, and there will only ever be 2 with the same merge_id</p>

<p>As I loop through the array I know I need to keep a variable that is always equal to the previous merge_id and if there is a match between previous and current, then merge.</p>

<pre><code>Array
(
    [0] =&gt; Array
        (
            [client_id] =&gt; 5
            [company_name] =&gt; company111_name
            [id] =&gt; 3
            [fee] =&gt; 111
            [year] =&gt; 2009
            [quarter] =&gt; 3
            [date_inserted] =&gt; 1264948583
            [description] =&gt; 2009 - Q3


            [fee_type] =&gt; 
            [merge_id] =&gt; a87ff679a2f3e71d9181a67b7542122c
            [total_paid] =&gt; 0
            [total_remainder] =&gt; 0
        )

    [1] =&gt; Array
        (
            [client_id] =&gt; 5
            [company_name] =&gt; company111_name
            [id] =&gt; 6
            [fee] =&gt; 55.5
            [year] =&gt; 2010
            [quarter] =&gt; 2
            [date_inserted] =&gt; 1264949470
            [description] =&gt; 2010 - Q2


            [fee_type] =&gt; 
            [merge_id] =&gt; a87ff679a2f3e71d9181a67b7542122c
            [total_paid] =&gt; 0
            [total_remainder] =&gt; 0
        )

    [2] =&gt; Array
        (
            [client_id] =&gt; 5
            [company_name] =&gt; company111_name
            [id] =&gt; 4
            [fee] =&gt; 111
            [year] =&gt; 2009
            [quarter] =&gt; 4
            [date_inserted] =&gt; 1264948583
            [description] =&gt; 2009 - Q4


            [fee_type] =&gt; 
            [merge_id] =&gt; 
            [total_paid] =&gt; 0
            [total_remainder] =&gt; 0
        )



    [3] =&gt; Array
        (
            [client_id] =&gt; 5
            [company_name] =&gt; company111_name
            [id] =&gt; 7
            [fee] =&gt; 55.5
            [year] =&gt; 2010
            [quarter] =&gt; 3
            [date_inserted] =&gt; 1264949470
            [description] =&gt; 2010 - Q3


            [fee_type] =&gt; 
            [merge_id] =&gt; 
            [total_paid] =&gt; 0
            [total_remainder] =&gt; 0
        )

)
</code></pre>

<p>Code</p>

<pre><code>$merger = $data['search']['0']['merge_id'];
            $i = 0;
            foreach($data['search'] as $fee)
            {
                if($fee['merge_id'] == $merger)
                {
                    //bump up &amp; merge arrays
                    ???
                }           

                $merger = $fee['merge_id'];
                $i++;
            }
</code></pre>
