Home  >  Article  >  Backend Development  >  How to use array_count_values ​​function in php

How to use array_count_values ​​function in php

藏色散人
藏色散人Original
2019-05-24 16:32:312677browse

Usage of array_count_values ​​function in php: [array_count_values(array)]. This function is used to count the number of occurrences of all values ​​in the array and return an array consisting of elements and the number of occurrences of the elements.

How to use array_count_values ​​function in php

php array_count_values ​​function is used to count all the values ​​in the array. Its syntax is array_count_values(array). The parameter array is required, which means that the values ​​need to be counted. Array of counts.

(Recommended tutorial: php video tutorial)

How to use the php array_count_values ​​function?

Function: Count all values ​​in the array

Syntax:

array_count_values(array)

Parameters:

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() function usage example 1

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

Output:

Array ( [php中文网] => 1 [西门] => 1 [讲师] => 1 )

php array_count_values() function usage example 2

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

Output:

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

The above is the detailed content of How to use array_count_values ​​function in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn