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;

Sum by two variables

In base R (for sum) there’s xtabs: > xtabs(sales ~ Date + area, mydf) area Date beijing shanghai 201204 41 23 201205 17 71 To get it as a data.frame, wrap it in as.data.frame.matrix. To update this with the approach that is making the rounds these days, you can also use a combination of “dplyr” … Read more