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 trialdaniwao
13,125 PointsWhat is wrong with this simple function?
I don't get what I'm missing? I'm following the format from PHP documentation for an array_sum. lol! Please help.
<?php
$numbers = array(1,5,8);
echo $array_sum($numbers);
?>
3 Answers
Kevin Korte
28,149 PointsThis line echo $array_sum($numbers);
is your problem.
array_sum
is a built in function of php, and thus does not need a $ sign. $ sign's assign or represent a variable. array_sum()
is a function, not a variable.
Here is a tested and correctly functioning answer.
<?php
$numbers = array(1,5,8);
echo array_sum($numbers);
?>
Jovanny Elias
16,204 Pointseach array item has to be inside double quotes. You also do not need a $ with $array.
daniwao
13,125 PointsI don't think with integers you have to put them in single or double quotes.
Jovanny Elias
16,204 PointsI may be wrong I am fairly new to php. Just starting to get the syntax of it.
Caleb King
32,777 Points<?php
$numbers = array(1,5,8);
echo $array_sum($numbers);
?>
daniwao
13,125 Pointsdaniwao
13,125 PointsYup, kicking myself in the butt, such a dumb mistake! Thanks for all the comments everyone and pitching in!
Kevin Korte
28,149 PointsKevin Korte
28,149 PointsNo problem. Simple error. We all do it.