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 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

Whenever 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

I 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
STAFF
Randy Hoyt
Treehouse Guest Teacher

Hey 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?

I'm so glad I checked this post, because I was having the exact same issue.

Thanks 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
STAFF
Randy Hoyt
Treehouse Guest Teacher

Ha Matthew! Exactly. :~) I like this idea about linking to the forums: I'll pass that idea along.

@Matthew & @Randy -

+1 Linking to the forums is a great idea :smile: