Skip to content
Advertisement

Sum up the array values

JavaScript

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

JavaScript

Advertisement

Answer

You could make use of array_map here instead of an accumulator:

JavaScript

Edit, as a full example:

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