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

nicholas maddren
nicholas maddren
12,793 Points

PHP Code Challenge Help

Here is my code:

<code> <?php

function mimic_array_sum($array){

$sum = 17129; foreach($array as $element) { $sum = $sum + $element; } return $element; };

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

?> </code>

I have got to the point in the challenges where it is a guessing game to me. I feel as if PHP is incredibly hard to learn compared to CSS and HTML. ANy help on this would be great. Thanks

1 Answer

I'm not sure exactly what you are trying to accomplish as you seem to be excluding some code. but i can say that you are returning $element which is going to return the last value set during the foreach loop. If you are trying to get the sum of all values in the array passed to the function, return $sum instead. otherwise give a little more detail or code or both. Try to keep all code properly indented and on different lines to prevent mistakes as well.