A simple loop is enough, select the repeated elements (the number of occurrences is greater than or equal to 2) and count the number of occurrences of each repeated element.
##The array_count_values() function in PHP can be implemented
array_count_values()The function is used to count the number of occurrences of all values in the array. (Recommended learning: PHP video tutorial)
This function returns an array, the key name of its element is the value of the original array, and the key value is the value in the original array the number of times it appears.
array_count_values(array)
For example:
<?php $a=array("Cat","Dog","Horse","Dog"); print_r(array_count_values($a)); ?>
Output:
Array ( [Cat] => 1 [Dog] => 2 [Horse] => 1 )
The above is the detailed content of How to unify a certain total in php. For more information, please follow other related articles on the PHP Chinese website!