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

How to use array_count_values ​​function in php

藏色散人
Release: 2023-02-22 18:14:02
Original
2691 people have browsed it

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)
Copy after login

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));
?>
Copy after login

Output:

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

php array_count_values() function usage example 2

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

Output:

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template