English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
array_count_values() The function is used to count the number of times all values appear in the array. It uses the values of the input array as keys, takes the number of times the value appears in the input array as the value, and returns an associative array of values.
array array_count_values ( array $input );
The key of the array is the value of the element in input; the value of the array is the number of times the value appears in input.
Serial Number | Parameters and Description |
---|---|
1 | input (required) Count the values of this array |
Returns an associative array using the values of the input array as keys, and the number of times the value appears in the array as the value.
This function was originally introduced in PHP 4Introduced in version .0.0.
Throw a warning error (E_WARNING) for each element in the array that is not a string or integer type.
Test the following array_count_values() example-
<?php $input = array("orange", "mango", "banana", "orange", "banana"); print_r(array_count_values($input)); ?>Test and See‹/›
Output Result:
Array ( [orange] => 2 [mango] => 1 [banana] => 2 )
Try the following example using all integer values-
<?php $input = array(10, 15, 30, 15, 10); print_r(array_count_values($input)); ?>Test and See‹/›
Output Result:
Array ( [10] => 2 [15] => 2 [30] => 1 )