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

what am i doing wrong?

In the main code, outside of the function, use the new mimic_array_sum() function you just wrote. Store the return value in a variable called $sum, and then display that sum to the screen.

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

3 Answers

Hi Cortney,

Check your spelling on the primes variable.

okay thank you.

Hi Cortney,

I really really hate it when that happens. Look at the code below: SPELLING. In fact when I pasted the code below the browser picked up the spelling error.

Jeff

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