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

what am I doing wrong?

<?php

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

$sum = 0; array_sum($numbers) { $numbers; }

echo $sum;

?>

2 Answers

Hayden Taylor
Hayden Taylor
5,076 Points

So the answer is....

<?php

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

$sum = 0;

$sum = array_sum($numbers);

echo $sum;

?>

And here is why. The question says that the function array_sum will calculate the sum of an array. So what you want to do is get rid of the for loop because you have a function now to do that same thing... and as you see you set the sum = to the return of that function (array_sum()).

Notice how we use a different line for each operation. You are trying to do to much on 1 line and confusing syntax.

I see that you have confusing calling a function and writing a function.

When you call a function it is usually function_name($Some_Parameter); and If you want what that function is doing captured in a variable like this question is asking you put the variable name = the function call. Like above.

When declaring a function it is...

function_name($some_parameter) { DO STUFF IN HERE return someSortaReturnValue; }

Hope this helps

Ohh!!!! Thank you so much!! I understand now!