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 trialMUZ140599 Rachael Tsaurai
5,406 Pointswhere am l missing it
i want to call a function called mimic_array_sum and then store the value in the variable $sum and then display the sum.
<?php
$sum;
function mimic_array_sum($array){
$a=0;
foreach($array as $element){
$a=$a+ $element;
}
return $a;
}
$sum = mimic_array_sum();
echo $sum;
$palindromic_primes = array(11, 757, 16361);
?>
1 Answer
Jason Brady
17,372 PointsYou've got all the pieces there... Your function requires an array to be passed into it. Here is something that would work...
<?php
$sum = 0;
$palindromic_primes = array(11, 757, 16361);
function mimic_array_sum($array){
$a=0;
foreach($array as $element){
$a += $element;
}
return $a;
}
$sum = mimic_array_sum($palindromic_primes);
echo $sum;
?>
Eric Buchmann
15,080 PointsEric Buchmann
15,080 PointsYour function mimic_array_sum requires a parameter to be passed to it, but when you call the function you aren't passing anything in. Try passing an array in to the function and see if it works then.