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

<?php $numbers = array(1,5,8); echo "Sum is :" . array_sum($numbers); ?>

how is this not correct?

sum.php
<?php

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

echo "Sum is :" . array_sum($numbers);

?>

3 Answers

Your answer is right, but you need to store the outcome into a variable and echo the variable. Like this.

<?php

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

$sum = array_sum($numbers);

echo $sum;

?>

so it need to be a variable...tnx

Cristian Altin
Cristian Altin
12,165 Points

It works fine the way you wrote it, here's the code in the PHP command line interface:

php > $num = array(1,5,8);
php > echo "Sum is :" . array_sum($num);
Sum is :14

I guess you needed to add a variable because of some requirements by the exercise or workings behind the scenes of the answer checker.