Home Menu

array_count_values

Counts all the values of an array

Syntax

array_count_values ( array $array ) : array

Parameters

array

The array of values to count

Return

Returns an associative array of values from array as keys and their count as value.

Examples

1

<?

$array = array(0, 0, 1, 0, 1, 2);

$return = array_count_values($array);

print_r($return);

?>
Array
(
    [0] => 3
    [1] => 2
    [2] => 1
)

2

<?

$array = array("a", "a", "b", "a", "b", "c");

$return = array_count_values($array);

print_r($return);

?>
Array
(
    [a] => 3
    [b] => 2
    [c] => 1
)

PHP

JesusBible
HTMLCSSJSPHPSVGMore
AboutTerms