I have a multidimensional array which looks like this:
Array
(
[0] => Array
(
[0] => Array
(
[description] => UPS Ground
[delivery-time] => 1-5 business days
[shipping-amount] => 1299
)
[1] => Array
(
[description] => UPS 3 Day Select
[delivery-time] => 3 business days
[shipping-amount] => 2459
)
[2] => Array
(
[description] => UPS 2nd Day Air
[delivery-time] => 2 business days
[shipping-amount] => 3239
)
)
[1] => Array
(
[0] => Array
(
[description] => UPS Ground
[delivery-time] => 1-5 business days
[shipping-amount] => 864
)
[1] => Array
(
[description] => UPS 3 Day Select
[delivery-time] => 3 business days
[shipping-amount] => 1109
)
[2] => Array
(
[description] => UPS 2nd Day Air
[delivery-time] => 2 business days
[shipping-amount] => 1633
)
[3] => Array
(
[description] => UPS Overnight
[delivery-time] => 1 business day
[shipping-amount] => 3528
)
)
)
I'm trying to achieve 3 things:
- Add the values of the
shipping-amountwhere thedescriptionis the same across dimensions - Drop the
arrayif it contains adescriptionwhich doesn't exist in every other dimension - Drop a dimension once the shipping-amounts are combined
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:
Array
(
[0] => Array
(
[description] => UPS Ground
[delivery-time] => 1-5 business days
[shipping-amount] => 2163
)
[1] => Array
(
[description] => UPS 3 Day Select
[delivery-time] => 3 business days
[shipping-amount] => 3568
)
[2] => Array
(
[description] => UPS 2nd Day Air
[delivery-time] => 2 business days
[shipping-amount] => 4872
)
)
Thanks in advance!
foreach,array_merge,array_map,key()but I don't know which order or functions make the most sense. I've had some great help for problems that challenge me here before, so I figured I'd ask again instead of wasting time putzing around.