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

Rob Salaman
Rob Salaman
1,915 Points

I can't preview because the preview button doesn't work

I'm not sure how to use the array_sum function and I was going to test through the preview button; however it's not working.

1 Answer

Hi Rob,

The array_sum() function takes any number values it finds in an array and sums them together. It has only one argument which is the array to get the sum of. So, with that in mind, you only need the $sum variable in order to store the sum from the array_sum() function and then echo that result out to the page:

$numbers = array(1,5,8);
//store the sum of the array in this variable
$sum = array_sum($numbers);
//then output to page
echo $sum;

Here is the reference for the array_sum() function: http://php.net/manual/en/function.array-sum.php

By the way, I believe the preview only works on client side languages because of the way the challenges are set up. I have yet to be able to use preview successfully in a server side challenge.

Rob Salaman
Rob Salaman
1,915 Points

Hi Marcus,

Thank you for your reply, this was perfect explanation thanks.

Also I suppose that makes sense.