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
Steve Linn
11,841 PointsMimic Array Sum code challenge 2 of 3
what the heck am I missing?
<?php
function mimic_array_sum($array) {
$sum=0;
foreach($array as $element) {
$sum = $sum + $element;
}
return $sum;
};
$palindromic_primes = array(11, 757, 16361);
$sum =$mimic_array_sum($palindromic_primes);
echo $sum;
?>
5 Answers
Steve Linn
11,841 Pointsalso, why are my cheats not working?
Shawn Gregory
Courses Plus Student 40,672 PointsHello,
First off you need to use the three back-ticks with the word 'php' appended to the back-ticks for it to work. Now for your question, you don't need a semicolon after the closing bracket ( } ) of the function. Take the semicolon out and the code should work. In real-life,this code would throw up a parsing error.
Cheers!
Steve Linn
11,841 Pointsstill no worky
i'm about to throw a parsing error
Shawn Gregory
Courses Plus Student 40,672 PointsHello,
Found your error. You have a $ in front of the function when you call it. Remove the $ from the function call and you should be good.
Cheers!
Steve Linn
11,841 Pointsoh yeah it's a function not a variable - cha-ching!