logo CodeStepByStep logo


Language/Type: PHP arrays
Author: Eric Roberts (added by Melissa Hovik on 2018/01/05)

Write a function named count_in_range that accepts parameters: an array of integers, a minimum integer, and a maximum integer. The function should return the number of elements in the array within the range of the given minimum and maximum values (inclusive).

For example, if the array $arr contains [28, 1, 17, 4, 41, 9, 59, 8, 31, 30, 25], the call of count_in_range($arr, 10, 30) should return 4. If the array is empty, return 0.

You may assume that the array passed is non-null and contains only integers. If the passed minimum value is greater than the passed maximum, your function should throw an Exception with the message, "Error: minumum must be less than or equal to maxiumum".

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.