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 trialLinda Woo
2,018 PointsA hint?
Am I going to create a function within a function? One function will allow me to cycle through the array - something like the mimic_count function in the video because I can't just assume the array will have three integers like the palindromic_primes array in the challenge. Then will I use this function to cycle through each number in the arrays? I will add $array[$count] + $array[... hmmm actually that won't work. As you can see, I am having a problem with this challenge.
1 Answer
Jeff Busch
19,287 PointsHi Linda,
With php's foreach loop you don't need a "count" variable. The foreach loop knows how many items are in the array. You're over-complicating things. Study the code below.
Jeff
<?php
function mimic_array_sum($array) {
$sum = 0;
foreach ($array as $num); {
$sum = $sum + $num;
}
return $sum;
}
$palindromic_primes = array(11, 757, 16361);
$total = mimic_array_sum($palindromic_primes);
echo $total;
?>
Linda Woo
2,018 PointsThank you, thank you!
Linda Woo
2,018 PointsLinda Woo
2,018 PointsHere's where I landed, and I know it's wrong....any hints?