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
Alejandro Carrillo
1,781 PointsBuild a Simple PHP Application > Working With Functions > Introducing User-Defined Functions 2/3
Hi, chaps...
Don't know whats wrong with my code in this challenge...
here's what I have:
<?php
function mimic_array_sum($array){
$sum = 0;
foreach($array as $element){
$sum = $sum + $element;
}
echo = $sum;
};
$palindromic_primes = array(11, 757, 16361);
?>
any idea?
Thanks
7 Answers
James Barnett
39,199 PointsWhenever you post about an issue with a PHP code challenge, 2 things are very helpful:
- A link to the code challenge you are having issues with
- A "working" example using a PHP sandbox
Joseph Cahill
Courses Plus Student 4,739 PointsI haven't done this challenge so I'm not exactly sure what you are trying to accomplish with it.
What I do see is it looks like $array is not defined anywhere. Is $palindromic_primes supposed to be $array?
Randy Hoyt
Treehouse Guest TeacherHey Alejandro,
The instructions say to have the mimic_array_sum function() return the sum. Right now, your function is echo'ing it instead.
Does that help?
Dustin Leer
21,063 PointsI'm so glad I checked this post, because I was having the exact same issue.
Matt Carr
9,654 PointsThanks for the clarification. I was stuck!
Perhaps each challenge should have a link to it's own forum/help topic. This would reduce redundant posts. Hey, that is kinda like PHP. I'm learning!
Randy Hoyt
Treehouse Guest TeacherHa Matthew! Exactly. :~) I like this idea about linking to the forums: I'll pass that idea along.
James Barnett
39,199 Points@Matthew & @Randy -
+1 Linking to the forums is a great idea