Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,867 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.