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
Daniel Fosco
4,916 PointsIntroducing User Defined Functions - Challenge Task 1 of 3
Hey there,
I'm really not getting the hang of this specific exercise:
In the previous code challenge “Introducing Functions,” we called PHP’s array_sum function to calculate the sum of the values in an array. In this code challenge, we’ll create a function that mimics that one. First, create a function named mimic_array_sum. It should receive one argument, an array of numbers to be summed. Name that argument $array. (Be sure to specify a pair of curly brackets where the code this function executes will go.)
I understand that I should add a mimic_array_sum( ) function, but other than that, I'm not really sure what else I should do. Here's my code:
<?php
mimic_array_sum($array) {
};
$palindromic_primes = array(11, 757, 16361);
?>
Any help is appreciated. Thanks!
5 Answers
Shawn Gregory
Courses Plus Student 40,672 PointsHello,
First off, as far as the semicolon at the end of the function goes, you can have it there if you want to as it is valid PHP code. Your issue stems from the declaration of the function. Remember, you are declaring/defining a function therefor you need the function keyword before the definition. The function keyword tells PHP that you are defining a function. Add the keyword in front of the function declaration and the challenge will pass.
Cheers!
David Andrews
17,403 PointsHey Dan..
Function looks fine apart from the semi-colon after the closing brace, remove that and you should be fine! :)
HTH.
Daniel Fosco
4,916 PointsHey David,
For some reason it's still not running :(
Any other ideas?
Thanks!
Daniel Fosco
4,916 PointsThat's it! Can't believe I forgot something so simple. I should sleep more, haha.
thanks a bunch!
Martin Mekhaiel
14,297 Points<?php
function mimic_array_sum($array) {
}
$palindromic_primes = array(11, 757, 16361);
?>
please help me what am I doing wrong?? lol