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

Matthew Smart
Matthew Smart
12,567 Points

stuck on php function challenge

This is the code i have for the challenge , i dont understand why it is not working , it says that my function isnt returning a value ?

<?php

function mimic_array_sum(){ $total = 0; foreach($primes as $prime){ $total = $total + $prime;

}

return $total; }

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

?>

2 Answers

Jeremy Germenis
Jeremy Germenis
29,854 Points

You are not passing a variable into your function. Also, you are not calling the function but I do not know if the challenge requires that or not.

Matthew Smart
Matthew Smart
12,567 Points

i know mate, ive tried so many different ways, i think its a bug in the actually website maybe?

could you watch the video and see if you can get past it? the video is literally 4 minutes long.

http://teamtreehouse.com/library/build-a-simple-php-application/working-with-functions/introducing-userdefined-functions

Jeremy Germenis
Jeremy Germenis
29,854 Points

Just completed the code challenge. You are not passing a variable in your function.

function myFunction($passedVariable) {
   echo $passedVariable;
}