Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKevin Parine
2,402 PointsIt's been a while... I have forgotten how to structure this.
help.
<?php
$numbers = array_sum(1,5,8);
$sum = 0;
$array_sum(($numbers as $number)) {
$sum = $sum + $number;
}
echo $sum;
?>
1 Answer
Felipe Giovanni de Moura Santos
23,702 PointsWhat's up man...
The array_sum() function receives an array "as its one and only argument" and returns the sum. So when calling it, you don't have to make it's logic for it, just pass an array as the parameter and do something with the returning value (in this case you could assign it to a variable or echo it out directly).
<?php
$numbers = array(1,5,8);
$sum = array_sum($numbers);
echo $sum;
?>
or, if the only reason for making the sum is to echoing it:
<?php
$numbers = array(1,5,8);
echo array_sum($numbers);
?>