我有數組並且不想分組一些數值。 我輸入數組:組數組並且總結一些數值
$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
)
)
)
)
);
我想要得到的東西是這樣的:
$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
)
)
);
我曾嘗試:
$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
);
}
}
}
但我有錯誤的結果...
謝謝你!!!!! – user889349
@ user889349當然很高興這有幫助 – Ghost