title: PHP sum array values with same keys
body: <p>This is the original main array:</p>
  
  <p>Array
  (</p>
  
  <pre><code>[0] =&gt; Array
  
      (
          [subtotal] =&gt; 0.6000
          [taxes] =&gt; 0.0720
          [charged_amount] =&gt; 0.6720
          [total_discount] =&gt; 0.0000
          [provinceName] =&gt; BC
          [store_key] =&gt; 1
          [store_id] =&gt; 5834
          [categories] =&gt; Array
              (
                  [2] =&gt; 0.6000
                  [4] =&gt; 0
                  [3] =&gt; 0
              )
  
      )
  
  [1] =&gt; Array
      (
          [subtotal] =&gt; 29.8500
          [taxes] =&gt; 2.3270
          [charged_amount] =&gt; 20.2370
          [total_discount] =&gt; 11.9400
          [provinceName] =&gt; MB
          [store_key] =&gt; 9
          [store_id] =&gt; 1022
          [categories] =&gt; Array
              (
                  [2] =&gt; 0
                  [4] =&gt; 29.8500
                  [3] =&gt; 0
              )
  
      )
  
  [2] =&gt; Array
      (
          [subtotal] =&gt; 0.3000
          [taxes] =&gt; 0.0390
          [charged_amount] =&gt; 0.3390
          [total_discount] =&gt; 0.0000
          [provinceName] =&gt; NB
          [store_key] =&gt; 8
          [store_id] =&gt; 1013
          [categories] =&gt; Array
              (
                  [2] =&gt; 0.3000
                  [4] =&gt; 0
                  [3] =&gt; 0
              )
  
      )
  
  [3] =&gt; Array
      (
          [subtotal] =&gt; 24.3100
          [taxes] =&gt; 1.1830
          [charged_amount] =&gt; 10.2830
          [total_discount] =&gt; 15.2100
          [provinceName] =&gt; NL
          [store_key] =&gt; 4
          [store_id] =&gt; 3033
          [categories] =&gt; Array
              (
                  [2] =&gt; 24.3100
                  [4] =&gt; 0
                  [3] =&gt; 0
              )
  
      )
  
  [4] =&gt; Array
      (
          [subtotal] =&gt; 1116.3400
          [taxes] =&gt; 127.6960
          [charged_amount] =&gt; 1110.0060
          [total_discount] =&gt; 134.0300
          [provinceName] =&gt; ON
          [store_key] =&gt; 2
          [store_id] =&gt; 1139
          [categories] =&gt; Array
              (
                  [2] =&gt; 85.7300
                  [4] =&gt; 143.2800
                  [3] =&gt; 887.3300
              )
  
      )
  
  [5] =&gt; Array
      (
          [subtotal] =&gt; 10.8500
          [taxes] =&gt; 1.4100
          [charged_amount] =&gt; 12.2600
          [total_discount] =&gt; 0.0000
          [provinceName] =&gt; ON
          [store_key] =&gt; 5
          [store_id] =&gt; 1116
          [categories] =&gt; Array
              (
                  [2] =&gt; 10.8500
                  [4] =&gt; 0
                  [3] =&gt; 0
              )
  
      )   
  </code></pre>
  
  <p>)</p>
  
  <p>I just need to add the values of the array [categories] with same keys and use it further to print the total, but not getting correct output, can someone help me out to get the desired result:</p>
  
  <p><strong>Desired result</strong></p>
  
  <p>An array with same keys but total of individual array values</p>
  
  <pre><code>Array ( [2] =&gt; 0.9000 [4] =&gt; 29.8500 [3] =&gt; 1.5 ) 
  </code></pre>
  
  <p>NOTE: Initial array is dynamic can have n number of key value pair</p>
  
  <p>Thanks</p>