Count the occurrences of a value in an array