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

Willie Allison
Willie Allison
2,035 Points

What is the treehouse way of doing this code? It works in my sublime text editor and spits out 17129

I can get the code to work in my sublime text editor but is not excepted in the treehouse check my work. What is the treehouse way of doing this?

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

1 Answer

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Well, you got the function right, but you didn't do what the problem is asking.

use the new mimic_array_sum() function you just wrote. Store the return value in a variable called $sum

you didn't call the mimic_array_sum function and store its return value to $sum.

<?php 

function mimic_array_sum($array) {
  $total = 0;
  foreach($array as $element) {
  $total= $total + $element;
  }
  return $total;
}

$palindromic_primes = array(11, 757, 16361);
$sum = mimic_array_sum($palindromic_primes);
echo $sum;
?>
Willie Allison
Willie Allison
2,035 Points

Thank you. You were right.

Willie Allison
Willie Allison
2,035 Points

Thank you. You were right.