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

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:

<?php
$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.