Usage of array_count_values function in php: [array_count_values(array)]. This function is used to count the number of occurrences of all values in the array and return an array consisting of elements and the number of occurrences of the elements.
php array_count_values function is used to count all the values in the array. Its syntax is array_count_values(array). The parameter array is required, which means that the values need to be counted. Array of counts.
(Recommended tutorial: php video tutorial)
How to use the php array_count_values function?
Function: Count all values in the array
Syntax:
array_count_values(array)
Parameters:
array required . Specifies the array of values to be counted.
Description:
is used to count the number of occurrences of all values in the array. This function returns an array, the key name of its element is the value of the original array, and the key value is the number of times the value appears in the original array.
php array_count_values() function usage example 1
<?php $a = array("class" => "php中文网","name" => "西门","job" => "讲师"); print_r(array_count_values($a)); ?>
Output:
Array ( [php中文网] => 1 [西门] => 1 [讲师] => 1 )
php array_count_values() function usage example 2
<?php $a=array("A","Cat","Dog","A","Dog"); print_r(array_count_values($a)); ?>
Output:
Array ( [A] => 2 [Cat] => 1 [Dog] => 2 )
The above is the detailed content of How to use array_count_values function in php. For more information, please follow other related articles on the PHP Chinese website!