-5

这是数组: http: //www.stylechica.de/array.rtf(我不能在这里复制)

我需要总结一下 ["PriceInformation"]["PriceInformation"]["PriceDetails"]["Price"] 并且已经尝试过各种类似的东西

foreach ($output["PriceInformation"]["PriceDetails"]["Price"] as $product)

echo array_sum($product);

但它只是行不通。有任何想法吗?

4

1 回答 1

0

Because $product refers to each iteration of $output["PriceInformation"]["PriceDetails"]["Price"], you can't sum the entire array like this. The best way to do it would be to add it to a variable as you go:

$your_sum = 0;
foreach($output as $value) {
    $your_sum += $value['PriceInformation']['PriceDetails']['Price'];
}
echo 'Sum: ' . $your_sum;
于 2013-10-15T23:44:58.927 回答