logo CodeStepByStep logo

find_mean

Language/Type: PHP arrays
Author: Eric Roberts (on 2018/01/05)

Write a function named find_mean that accepts an array of numbers as a parameter and returns the arithmetic mean (average) of the numbers in the array.

For example, if the array passed contains [2, 4.5, 6.5, 1], your function should return 3.5. If it instead contained [2, 2, 2] it should return 2.

If the array is empty, your function should return 0.

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.