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

daniwao
daniwao
13,125 Points

What is wrong with this simple function?

I don't get what I'm missing? I'm following the format from PHP documentation for an array_sum. lol! Please help.

<?php

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

echo $array_sum($numbers);

?>

3 Answers

Kevin Korte
Kevin Korte
28,148 Points

This line echo $array_sum($numbers); is your problem.

array_sum is a built in function of php, and thus does not need a $ sign. $ sign's assign or represent a variable. array_sum()is a function, not a variable.

Here is a tested and correctly functioning answer.

<?php
$numbers = array(1,5,8);

echo array_sum($numbers);
?>
daniwao
daniwao
13,125 Points

Yup, kicking myself in the butt, such a dumb mistake! Thanks for all the comments everyone and pitching in!

Kevin Korte
Kevin Korte
28,148 Points

No problem. Simple error. We all do it.

each array item has to be inside double quotes. You also do not need a $ with $array.

daniwao
daniwao
13,125 Points

I don't think with integers you have to put them in single or double quotes.

I may be wrong I am fairly new to php. Just starting to get the syntax of it.

<?php

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

echo $array_sum($numbers);

?>