Latest web development tutorials

PHP array_count_values ​​() function

PHP Array Reference Complete PHP Array Reference

Examples

Statistical values ​​in an array number of occurrences:

<?php
$a=array("A","Cat","Dog","A","Dog");
print_r(array_count_values($a));
?>

Running instance »

Definition and Usage

array_count_values ​​() function is used to count the number of values ​​in an array appearing.


grammar

array_count_values( array )

参数 描述
array 必需。规定需要统计数组中所有值出现次数的数组。

technical details

return value: Returns an associative array, key elements of which is the value of the original array, the key is the number of occurrences of the value in the original array.
PHP version: 4+


PHP Array Reference Complete PHP Array Reference