I have array and wan't to group some values. My input array:
$input =
(
[0] => Array (
[shipping] => Array
(
[ups] => Array
(
[0] => Array
(
[name] => Next Day Air (early AM)
[code] => 14
[price] => 110.00
)
[1] => Array
(
[name] => Next Day Air
[code] => 01
[price] => 105.25
)
)
)
)
[1] => Array (
[shipping] => Array
(
[ups] => Array
(
[0] => Array
(
[name] => Next Day Air (early AM)
[code] => 14
[price] => 120.00
)
[1] => Array
(
[name] => Next Day Air
[code] => 01
[price] => 105.50
)
)
)
)
);
I'm trying to get something like this:
$shipping_group = array (
[ups] => Array
(
[0] => Array
(
[name] => Next Day Air (early AM)
[code] => 14
[price] => 230.00
)
[1] => Array
(
[name] => Next Day Air
[code] => 01
[price] => 210.75
)
)
);
What I have tried:
$shipping_ups_total = array();
foreach($input as $box) {
$box = (object)$box;
if (!empty($box->shipping['ups'])) {
foreach($box->shipping['ups'] as $m=>$method) {
$price += $method['price'];
$shipping_ups_total[$m] = array(
'name' => $method['name'],
'code' => $method['code'],
'price' => $price
);
}
}
}
But I have wrong results...