Home >Backend Development >PHP Tutorial >php-Arrays function-array_count_values-counts the occurrences of all values in an array_PHP tutorial
array_count_values() function
【Function】
This function will return an array,
This array uses the value in the input array as the key name,
The number of times this value appears in the input array is used as the value
【Scope of use】
php4, php5
【Use】
array array_count_values(array input)
× × × × × / × / × ‐ [ 〉
【Example】
[php]
$arr = array( "key1" => "val1", "key2" => "val2",
"key3" => "val1", "key4" => "val4" );
print_r( array_count_values( $arr ) );
/*
Array
(
[val1] => 2
[val2] => 1
[val4] => 1
)
*/
Excerpted from zuodefeng’s notes