Skip to content
Advertisement

Tag: sum

Accumulate monthly totals while looping

I have an array of data containing monthly amounts from the current year and the previous year. The previous year always has all of its amounts, but when a current/future month in the current year is iterated it has a null value. Here is an example: This is my current code How can I roll previous month amounts into current

adding values in an array from SQL result

I’m trying to put the user_value in an array if the affiliate_id=50. Then add up the array with the sum function. The issue is the array only has one of the user values inside it. My question is how …

Sum up the array values

I am working on a custom module in drupal and need to sum up the [value], However I tried different approaches using array_column, array_sum, but didn’t get the solution. Any help would be appreciated. Thanks. Code Answer You could make use of array_map here instead of an accumulator: Edit, as a full example:

Advertisement