php array_count_values() function


  Translation results:

UK['væljʊz] US['væljʊz]

n. Value; concept of value; view of value; criterion; standard; value (plural form of value); standard of value; (currency, stamps etc.) Face value

v. Valuation (the third person singular of value); attach importance to; price...; evaluate

php array_count_values() functionsyntax

Function:Count all values ​​in the array

Syntax: array_count_values(array)

Parameters :

Parameter Description
array Required. Specifies the array of values ​​to be counted.

Description: is used to count the number of occurrences of all values ​​in the array. This function returns an array, the key name of its element is the value of the original array, and the key value is the number of times the value appears in the original array.

php array_count_values() functionexample

<?php
$a = array("class" => "php中文网","name" => "西门","job" => "讲师");
print_r(array_count_values($a));
?>

Run instance»

Click the "Run instance" button to view the online instance

Output:

Array ( [php中文网] => 1 [西门] => 1 [讲师] => 1 )
<?php
$a=array("A","Cat","Dog","A","Dog");
print_r(array_count_values($a));
?>

Run Instance»

Click the "Run Instance" button to view the online instance

Output:

Array ( [A] => 2 [Cat] => 1 [Dog] => 2 )

Home

Videos

Q&A