Skip to content
Advertisement

Php sum a multidimensional array to itself

I want to sum entries to an array (dynamic array, data being taken from the database) and return sum of each entry. The multidimensional array has the following shape:

JavaScript

What I want to do is add the values of the sample array in “term_1_mid” to the values of the same sample array in “term_1_end”… So the resulting summation output should be something like:

JavaScript

Is there any way I could achieve this?

I tried the following code but it doesn’t seem to work:

JavaScript

Advertisement

Answer

Here is the solution for the problem.

JavaScript

Output :

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