【发布时间】:2021-12-02 15:18:31
【问题描述】:
我有这个
foreach ($item_id as $key => $no) {
$input['price'] = $price[$key]['price'];
$input['quantity'] = $quantity[$key];
$subtotal[] = [$input['price']*$input['quantity']];
}
$total_price = array_sum($subtotal);
当我dd($total_price) 它返回0。
当我dd($subtotal) 时,它会像这样返回我的数组
array:3 [▼
0 => array:1 [▼
0 => 3000000
]
1 => array:1 [▼
0 => 3
]
2 => array:1 [▼
0 => 9
]
]
我如何从中总结我的数组?谢谢!
【问题讨论】:
-
避免将数组添加到小计,例如
$subtotal[] = $input['price']*$input['quantity'],它应该可以工作。
标签: php arrays laravel laravel-8