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 trialCortney Burgess
10,758 PointsI do not understand..help
In the previous code challenge “Introducing Functions,” we called PHP’s array_sum function to calculate the sum of the values in an array. In this code challenge, we’ll create a function that mimics that one. First, create a function named mimic_array_sum. It should receive one argument, an array of numbers to be summed. Name that argument $array. (Be sure to specify a pair of curly brackets where the code this function executes will go.)
<?php
$palindromic_primes = array(11, 757, 16361);
?>
1 Answer
Natasha McDiarmid
11,400 PointsGive this a shot:
<?php
function mimic_array_sum($array) {
$sum = 0;
foreach($array as $element) {
$sum = $sum + $element;
}
return $sum;
}
$palindromic_primes = array(11, 757, 16361);
?>