[SOLVED] Array Adding

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

Post Reply
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Array Adding

Post 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 8)
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

[php_man]array_sum[/php_man]
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Code: Select all

echo array_sum($array);
http://php.net/array_sum

edit: stupid people being stupid faster than me.. stupid. :D
Last edited by d3ad1ysp0rk on Tue Jul 13, 2004 10:05 am, edited 2 times in total.
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post 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 :)
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post 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.
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

:O whooops (the forums are just a quick reference to me)
Post Reply