SUM of array

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have an array filled with data. I need to sum it's value.

example: $key1=>10, $key2=>15, $key3=>5

I want the total of all values which should be: 30

Re: SUM of array

Quoted text here. Click to load it


"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirvi  

Re: SUM of array

I want to get the sum of the array key values.

ex: $key1=>10, $key2=>15, $key3=>5

I want variable $sum = 30.

any solution?

Re: SUM of array

Maximus wrote:
Quoted text here. Click to load it

Kimmo already supplied the solution; with associative arrays, use it with :

$array = array('key1'=10, 'key2'=15, 'key3'=5);
$sum = array_sum(array_values($array));


Site Timeline