$array = array("Kyle","Ben","Sue","Phil","Ben","Mary","Sue","Ben");
$counts = array_count_values($array);
echo $counts['Ben'];
Answer from Rajat Singhal on Stack Overflow
๐ŸŒ
PHP
php.net โ€บ manual โ€บ en โ€บ function.array-count-values.php
PHP: array_count_values - Manual
array_count_values() returns an array using the values of array (which must be ints or strings) as keys and their frequency in array as values.
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ php โ€บ arrays โ€บ array_count_values()
PHP | Arrays | array_count_values() | Codecademy
August 8, 2023 - The array_count_values() is a function that counts the occurrences of values in an array.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ php โ€บ php-array_count_values-function
PHP array_count_values() Function - GeeksforGeeks
June 20, 2023 - The array_count_values() is an inbuilt function in PHP which is used to count all the values inside an array. In other words we can say that array_count_values() function is used to calculate the frequency of all of the elements of an array.
๐ŸŒ
ZetCode
zetcode.com โ€บ php-array โ€บ array-count-values
PHP array_count_values - Counting Array Values in PHP
The PHP array_count_values function counts the occurrences of values in an array.
๐ŸŒ
Medium
medium.com โ€บ @ok4304571 โ€บ php-array-count-values-function-730a683fc19b
PHP array_count_values() Function - Ok - Medium
June 14, 2025 - The array_count_values() function returns an array where the keys are the original arrayโ€™s values, and the values is the number ofโ€ฆ
Find elsewhere
๐ŸŒ
Reintech
reintech.io โ€บ blog โ€บ phps-array-count-values-function-complete-guide
PHP's `array_count_values()` Function: A Complete Guide
April 14, 2023 - This function excels at transforming arrays into frequency distributions with minimal code. In scenarios ranging from text analysis to e-commerce product popularity tracking, understanding how to leverage array_count_values() effectively can significantly streamline your data processing workflows.
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ php โ€บ php_function_array_count_values.htm
PHP array_count_values() Function
The array_count_values() function returns an associative array of values using the values of the input array as keys and their frequency in input array as values. It returns an associative array of values from input as keys and their count as value.
๐ŸŒ
Lsu
ld2014.scusa.lsu.edu โ€บ php โ€บ function.array-count-values.html
Counts all the values of an array
array_count_values() returns an array using the values of array as keys and their frequency in array as values.