title: PHP how to aggregate 2 dimensional array
body: <p>I have a 2D array in PHP, I need to aggregate the data inside it before saving it into an EXCEL sheet with PHPExcel. My data is already sorted by country. Each sub-array has a country name. what I want to do is to add a total number of the field "LIVE" per country. My table looks like this:  </p>
  
  <pre><code>[
      [314] =&gt; Array
              (
                  [Country] =&gt; France
                  [provider] =&gt; HIberica
                  [status] =&gt; inactive
                  [# per status] =&gt; 1
                  [Live] =&gt; 0
              )
  
          [315] =&gt; Array
              (
                  [Country] =&gt; France
                  [provider] =&gt; HIberica
                  [status] =&gt; active
                  [# per status] =&gt; 4223
                  [Live] =&gt; 4171
              )
  
          [316] =&gt; Array
              (
                  [Country] =&gt; United States
                  [provider] =&gt; HarperC
                  [status] =&gt; pending
                  [# per status] =&gt; 69
                  [Live] =&gt; 0
              )
  
          [317] =&gt; Array
              (
                  [Country] =&gt; United States
                  [provider] =&gt; HC
                  [status] =&gt; inactive
                  [# per status] =&gt; 2582
                  [Live] =&gt; 0
              )
  
          [318] =&gt; Array
              (
                  [Country] =&gt; United States
                  [provider] =&gt; HC
                  [status] =&gt; active
                  [# per status] =&gt; 16217
                  [Live] =&gt; 16217
              )
  
          [319] =&gt; Array
              (
                  [Country] =&gt; United States
                  [provider] =&gt; H UK
                  [status] =&gt; active
                  [# per status] =&gt; 70
                  [Live] =&gt; 70
              )
  
  ]
  </code></pre>
  
  <p>The end-result that I want is adding a sub-array for each country to hold the total of LIVE field, just like this: </p>
  
  <pre><code> [320] =&gt; Array
                  (
                      [Country] =&gt; United States
                      [provider] =&gt; All Providers
                      [status] =&gt; active
                      [# per status] =&gt; NULL
                      [Total Live] =&gt; 7000 # the total per country goes here
                  )
  </code></pre>
  
  <p>I know that PHP functions like <code>array_walk_recursive</code> could help but I don't know how to do it. </p>