title: Sum of elements in multidimensional array
body: <p><strong>I have the following input:</strong></p>
  
  <pre><code>$data = array(
      0 =&gt; array(
          'date' =&gt; '2014-01-01',
          'sales' =&gt; 1,
          'price' =&gt; array(
              'usd' =&gt; 1,
              'eur' =&gt; 100
          )
      ),
      1 =&gt; array(
          'date' =&gt; '2014-01-05',
          'sales' =&gt; 1,
          'price' =&gt; array(
              'usd' =&gt; 1,
              'eur' =&gt; 100,
              'gbp' =&gt; 500
          )
      ),
      2 =&gt; array(
          'date' =&gt; '2016-03-27',
          'sales' =&gt; 5,
          'age' =&gt; 50
      ),
      3 =&gt; array( 
          'date' =&gt; '2016-03-28',
          'sales' =&gt; 10
      )
  );
  </code></pre>
  
  <p><strong>And I expect the following output:</strong></p>
  
  <pre><code>$final = array(
      'March 2016' =&gt; array(
          'sales' =&gt; 15
      ),
      'January 2014' =&gt; array(
          'sales' =&gt; 2,
          'price' =&gt; array(
              'usd' =&gt; 2,
              'eur' =&gt; 200,
              'gbp' =&gt; 500
          )
      )
  );
  </code></pre>
  
  <p><strong>What I've done so far?</strong></p>
  
  <pre><code>$monthlyData = array();
  
  foreach ($dailyData as $day)
  {
      $key = date('M y', strtotime($day['date']));
  
      if (!isset($monthlyData[$key]))
      {
          $monthlyData[$key] = $day;
          continue;
      }
  
      foreach ($day as $metric =&gt; $value)
      {
          if(!empty($value)) 
          {
              $monthlyData[$key][$metric] += $value;
          }
      }
  }
  </code></pre>
  
  <p>Well, I know that we can use good ol' <code>foreach</code> (with recursive calls) in order to get the right result, but I'm looking for some more elegant solution.</p>