PHP Array Sum

July 10, 2008

I was needing to sum all the values in an array today. I was about to make my own function to do this when I found out that PHP has a built in function called array_sum that does that for you.

Here’s an example.

Let’s say you have an array like this.

$bingo = array(’1′,’2′,’3′);

Well to sum up those numbers you’d do this.

$bingo_sum = array_sum($bingo);

And that’s it. Easy huh?

Got something to say?

You must be logged in to post a comment.