PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Joe
Forum Regular
Posts: 939 Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow
Post
by Joe » Tue Jul 13, 2004 10:00 am
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
redmonkey
Forum Regular
Posts: 836 Joined: Thu Dec 18, 2003 3:58 pm
Post
by redmonkey » Tue Jul 13, 2004 10:03 am
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.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Jul 13, 2004 10:03 am
[php_man]array_sum[/php_man]
Joe
Forum Regular
Posts: 939 Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow
Post
by Joe » Tue Jul 13, 2004 10:04 am
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
redmonkey
Forum Regular
Posts: 836 Joined: Thu Dec 18, 2003 3:58 pm
Post
by redmonkey » Tue Jul 13, 2004 10:08 am
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.
Joe
Forum Regular
Posts: 939 Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow
Post
by Joe » Tue Jul 13, 2004 10:17 am
:O whooops (the forums are just a quick reference to me)