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 trial

PHP Build a Simple PHP Application Working With Functions Introducing Functions

array_sum confusion

I cannot, for the life of me, understand what I am doing wrong. I'm ready to skip this challenge but I'd prefer to know what it is that I don't understand.


$numbers = array(1,5,8);


echo $sum;


2 Answers

Simon Woodard
Simon Woodard
6,545 Points

You haven't stored anything in the variable $sum so it wont echo anything out :)

Thanks Simon!

I wrote $sum = array_sum($numbers); and that did the trick!

I was having trouble with how the array_sum function operates, but I think resolving this challenge helped my understanding.

Thanks again! :)

Alex Heil
Alex Heil
53,547 Points

hey Eric Chunn , actually you're pretty close to the right answer and Simon Woodard gave a good hint. To "sum" this up: You have successfully replaced the old loop and replaced it with the array_sum function. You also passed in the numbers array correctly, what's missing is the assignment of that function to a variable, like this:

$sum = array_sum($numbers);

then you could echo it out and the challenge would pass just fine. hope that helps and have a nice day ;)