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 User-Defined Functions

Aaron Jackson
Aaron Jackson
5,644 Points

Stumped on code Challenge...

I have been trying to get through this code challenge for a few days and I am completely stumped right now. Can someone tell me why my code won't pass?

function mimic_array_sum($array) {
  $total = 0;
  foreach($array to $element) {
  $total = $total + $element;
  }
  return $total;
}

$palindromic_primes = array(11, 757, 16361);
echo mimic_array_sum($palindromic_primes);

?>

2 Answers

Erik McClintock
Erik McClintock
45,783 Points

Aaron,

In your foreach loop, you have the keyword "to" - this should be "as".

Try that and see if it passes?

Erik

Erik McClintock
Erik McClintock
45,783 Points

Beyond that, if you've gotten to the third section of the challenge, it wants you to store the value returned by mimic_array_sum into a variable called $sum, and then wants you to echo that value to the screen.

Aaron Jackson
Aaron Jackson
5,644 Points

Thanks Erik that was the problem!!

Erik McClintock
Erik McClintock
45,783 Points

Glad I could help! Happy coding!

Erik