Sum up array values [closed]

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;

Leave a Comment