array sum-up and traversal issue
<p>I have a 3rd party app, whose API return data in form of array as:</p>

<pre><code>Array
(
[2011-03-26] =&gt; Array
    (
    )

[2011-03-27] =&gt; Array
    (
    )

[2011-03-28] =&gt; Array
    (
        [0] =&gt; Array
            (
                [label] =&gt; apples
                [eaten] =&gt; 2
                [noteaten] =&gt; 2
                [rotten] =&gt; 2
            )

    )

[2011-03-29] =&gt; Array
    (
        [0] =&gt; Array
            (
                [label] =&gt; apples
                [eaten] =&gt; 2
                [noteaten] =&gt; 2
                [rotten] =&gt; 7
            )

    )

[2011-03-30] =&gt; Array
    (
    )

[2011-03-31] =&gt; Array
    (
        [0] =&gt; Array
            (
                [label] =&gt; apples
                [eaten] =&gt; 1
                [noteaten] =&gt; 1
                [rotten] =&gt; 4
            )

    )

[2011-04-01] =&gt; Array
    (
        [0] =&gt; Array
            (
                [label] =&gt; bananas
                [eaten] =&gt; 18
                [noteaten] =&gt; 18
                [rotten] =&gt; 18
            )

        [1] =&gt; Array
            (
                [label] =&gt; apples
                [eaten] =&gt; 6
                [noteaten] =&gt; 7
                [rotten] =&gt; 31
            )

        [2] =&gt; Array
            (
                [label] =&gt; oranges
                [eaten] =&gt; 1
                [noteaten] =&gt; 1
                [rotten] =&gt; 9
            )

    )

[2011-04-02] =&gt; Array
    (
    )

[2011-04-03] =&gt; Array
    (
    )

[2011-04-04] =&gt; Array
    (
        [0] =&gt; Array
            (
                [label] =&gt; bananas
                [eaten] =&gt; 24
                [noteaten] =&gt; 27
                [rotten] =&gt; 27
            )

        [1] =&gt; Array
            (
                [label] =&gt; apples
                [eaten] =&gt; 2
                [noteaten] =&gt; 3
                [rotten] =&gt; 8
            )

    )

)
</code></pre>

<p>Now, I need to find out total eaten and not-eaten for each fruit (i.e, label here) over the particular course of time like</p>

<pre><code>fruit              eaten               noteaten 
------------------------------------------------
apples              15                   20
bananas             30                   12
</code></pre>

<p>I have written 2 foreach loops: first one for outer array (one which have dates as key), and another one for each date (see 2011-04-01, it has 3 sub-elements)</p>

<p>but this solution is not optimal. It takes lots of time.</p>

<p>Is there any other way to achieve following? Any optimal way?</p>

<p>EDIT: This is just a sample data, original data may span upto 100 or more days. At that time process takes lots of time.</p>

<p>EDIT 2:</p>

<p>$result is where I get my data from 3rd party API</p>

<pre><code>$output_arr = array();

foreach($result as $date_arr) {
 foreach ($date_arr as $date_values) {
     if (isset($output_arr[$date_values['label']]))
        $output_arr[$date_values['label']] += $date_values['eaten'];
     else
        $output_arr[$date_values['label']] = $date_values['eaten'];
 }
}
</code></pre>
