- ARRAY_COUNT_VALUES
array_count_values
— Counts all the values of an array
Description
array array_count_values
( array $input )
array_count_values() returns an
array using the values of the input array as keys and their frequency in
input as values.
Parameters
input
The array of values to count
Return Values
Returns an
assosiative array of values from input as keys and their count as value.
Errors/Exceptions
<?php $array = array(1, "hello", 1, "world", "hello"); print_r(array_count_values($array)); ?> Out Put Array ( [1] => 2 [hello] => 2 [world] => 1 ) <?php $array = array(1, "hello", 1, "world", "hello"); $a = array_count_values($array); foreach ($a as $k => $v) { echo "key is $k number of value is $v <br>"; } ?> The above example will output: key is 1 number of value is 2 key is hello number of value is 2 key is world number of value is 1
Tags
ARRAY_COUNT_VALUES