Skip to content
Advertisement

Sum array values

I’m making a shipping service app to Shopify and my callback URL have this JSON post using json_decode to make an array. The value I want to sum is grams and putting into variable and then compare with the value of another variable using if ($weight <= $maxweight).

JavaScript

Advertisement

Answer

You just need a simple foreach then under the loop, just add the value. Consider this example:

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