Page 1 of 1
Array Adding
Posted: Tue Jul 13, 2004 10:00 am
by Joe
Is it possible to add all of the numbers in an array. For example:
array(1,2,3);
And after adding them up the answer would obviously be 6. Is this possible? If so then could someone please lead me in the right direction.
Regards
Joe

Posted: Tue Jul 13, 2004 10:03 am
by redmonkey
Code: Select all
<?php
echo array_sum(array(1,2,3));
?>
A quick flick through the Array section of the manual would probably have helped you.
Posted: Tue Jul 13, 2004 10:03 am
by feyd
[php_man]array_sum[/php_man]
Posted: Tue Jul 13, 2004 10:04 am
by d3ad1ysp0rk
http://php.net/array_sum
edit: stupid people being stupid faster than me.. stupid.

Posted: Tue Jul 13, 2004 10:04 am
by Joe
Yeah I tried to look, call me dumb but I couldn't find anything which was of any use to me. Anyway, Thanks for your help guys. Problem Solved

Posted: Tue Jul 13, 2004 10:08 am
by redmonkey
www.php.net/array is the first page of the array section. It also lists all array functions. From that page....
www.php.net/array wrote:
array_sum -- Calculate the sum of values in an array.
Call me what you will but, I think that's a hint.
Posted: Tue Jul 13, 2004 10:17 am
by Joe
:O whooops (the forums are just a quick reference to me)