Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,534 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 ;)