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 trialWillie Allison
2,035 PointsWhat 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?
<?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
Courses Plus Student 26,868 PointsWell, 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
2,035 PointsWillie Allison
2,035 PointsThank you. You were right.
Willie Allison
2,035 PointsWillie Allison
2,035 PointsThank you. You were right.