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

challenge. 3. of. 3.. how. do. i. answer. this. question

how. do. i. answer. this. question

palindromic_primes.php
<?php 
function mimic_array_sum($array){
    $sum=0;
  foreach($array as $element){
         $sum = $sum + $element;                   
     }
    return $sum;
 }
$sum = mimic_array_sum($palindromic_primes);
echo $sum;


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

?>

1 Answer

Jeff Lemay
Jeff Lemay
14,268 Points

It looks like you just need to move your $palindromic_primes array above the lines where you call the function and echo the result.

With how your code is now, you are running the function and trying to echo the sum before your array has been set, so your palindromic_primes aren't being passed into the function.

Jeff Lemay
Jeff Lemay
14,268 Points
<?php 
function mimic_array_sum($array){
    $sum=0;
  foreach($array as $element){
         $sum = $sum + $element;                   
     }
    return $sum;
 }
// set the array values
$palindromic_primes = array(11, 757, 16361);

// run the function and pass in the array values set above
$sum = mimic_array_sum($palindromic_primes);

// print the value produced by the function
echo $sum;



?>