foreach($formattedDatas as $key => $formattedData) {
foreach ($formattedData as $keyFormat => $valueFormat) {
$brandDataArray['sales_price'] += $valueFormat['total_price'];
}
}
我收到了这个通知:
A PHP Error was encountered
Severity: Notice
Message: Undefined index: sales_price
Filename: models/sales_aggregated.php
Line Number: 34
有人可以帮我解决这个问题吗?
答案 0 :(得分:0)
在尝试添加$brandDataArray['sales_price']
之前对其进行初始化。
// Assuming the array $brandDataArray already exists.
// If not, initialize that too!
$brandDataArray['sales_price'] = 0;
// Then proceed...
foreach($formattedDatas as $key => $formattedData) {
foreach ($formattedData as $keyFormat => $valueFormat) {
$brandDataArray['sales_price'] += $valueFormat['total_price'];
}
}