Skip to content
Advertisement

Calculate foreach group in loop by 3 PHP

Hope you are doing great! Please have an idea of ​​a comment grouped by 3, then the 4th to receive the value of the grouped in a month. This my dat below :

JavaScript

I tryed this code : Sum Value in foreach loop every 3 time looping

But i don’t know specify the 4th with the sum, to loop in my view

If possible, i want this :

JavaScript

I try this code :

JavaScript

And the result is :

JavaScript

Advertisement

Answer

A (very) basic solution (for my tests, I fix the typo on February month name) :

JavaScript

The result is

JavaScript

The getNextMonth may be the only piece of code you need to add to your own code 🙂

Pretty sure that there are shorter (and more elegant) solutions, but hope that helps anyway.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement