logo CodeStepByStep logo

even_average

Language/Type: PHP arrays
Author: Melissa Hovik (on 2018/01/05)

Write a function named even_average which takes an array of integers as a parameter and returns the average of all even integers in the array.

For example, a call of even_average([1, 2, 3, 4, 8, 7, 6, 6]) should return 5.2 (since only the five values 2, 4, 6, 6, and 8 are considered in the calculation of the average result) and even_average([5, 4, 3]) should return 4 since 4 is the only even integer in the array.

If the array passed is empty or does not contain any even integers, return 0. You may assume the array passed is non-null.

Function: Write a PHP function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.