title: Combining Multidimensional Array Values in PHP
body: <p>I have a multidimensional array which looks like this:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [0] =&gt; Array
                  (
                      [description] =&gt; UPS Ground
                      [delivery-time] =&gt; 1-5 business days
                      [shipping-amount] =&gt; 1299
                  )
  
              [1] =&gt; Array
                  (
                      [description] =&gt; UPS 3 Day Select
                      [delivery-time] =&gt; 3 business days
                      [shipping-amount] =&gt; 2459
                  )
  
              [2] =&gt; Array
                  (
                      [description] =&gt; UPS 2nd Day Air
                      [delivery-time] =&gt; 2 business days
                      [shipping-amount] =&gt; 3239
                  )
          )
  
      [1] =&gt; Array
          (
              [0] =&gt; Array
                  (
                      [description] =&gt; UPS Ground
                      [delivery-time] =&gt; 1-5 business days
                      [shipping-amount] =&gt; 864
                  )
  
              [1] =&gt; Array
                  (
                      [description] =&gt; UPS 3 Day Select
                      [delivery-time] =&gt; 3 business days
                      [shipping-amount] =&gt; 1109
                  )
  
              [2] =&gt; Array
                  (
                      [description] =&gt; UPS 2nd Day Air
                      [delivery-time] =&gt; 2 business days
                      [shipping-amount] =&gt; 1633
                  )
               [3] =&gt; Array
                  (
                      [description] =&gt; UPS Overnight
                      [delivery-time] =&gt; 1 business day
                      [shipping-amount] =&gt; 3528
                  )
  
          )
  
  )
  </code></pre>
  
  <p>I'm trying to achieve 3 things:</p>
  
  <ol>
  <li>Add the values of the <code>shipping-amount</code> where the <code>description</code> is the same across dimensions</li>
  <li>Drop the <code>array</code> if it contains a <code>description</code> which doesn't exist in every other dimension</li>
  <li>Drop a dimension once the shipping-amounts are combined</li>
  </ol>
  
  <p>There may be several first-level arrays (not just 2 as shown here), but this is as deep as the dimensions will go. I'm looking for the following result:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [description] =&gt; UPS Ground
              [delivery-time] =&gt; 1-5 business days
              [shipping-amount] =&gt; 2163
          )
      [1] =&gt; Array
          (
              [description] =&gt; UPS 3 Day Select
              [delivery-time] =&gt; 3 business days
              [shipping-amount] =&gt; 3568
          )
      [2] =&gt; Array
          (
              [description] =&gt; UPS 2nd Day Air
              [delivery-time] =&gt; 2 business days
              [shipping-amount] =&gt; 4872
          )
  ) 
  </code></pre>
  
  <p>Thanks in advance!</p>