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

Chris Sunde
Chris Sunde
10,680 Points

function lost($mimic_array_sum)

I keep getting step 2 of the code challenge wrong. Usually, I can get close enough that I'm given a hint. I'm so far off that all I get is "Bummer! Try again!" ("Bummer" is not very helpful). If I had to guess, I think I'm misunderstanding the difference between my function variables, my working variables, my argument, and my variables outside the function.

Hi Chris,

Would like to see your code.

Jeff

Chris Sunde
Chris Sunde
10,680 Points
 <?php 

function mimic_array_sum($array) {

    $sum = 0;
    foreach($array as $element) {
    $sum = $sum + $array; 
    }
    return $sum;  
}
$palindromic_primes = array(11, 757, 16361);
$sum = mimic_array_sum($palindromic_primes);
echo $sum;
?>

1 Answer

OK Chris,

You are soooo close. You have a working variable ($element) you are not using. In the statement inside the foreach loop replace $array with $element.

Jeff

Chris Sunde
Chris Sunde
10,680 Points

Worked like a charm! Thanks, Jeff!