Home > Backend Development > PHP Tutorial > The array_count_values() function counts the number of repetitions of array values

The array_count_values() function counts the number of repetitions of array values

php中世界最好的语言
Release: 2023-03-27 07:10:02
Original
1514 people have browsed it

This time I will bring you the array_count_values() function to count the number of times the array value is repeated. What are the precautions for the array_count_values() function to count the number of times the array value is repeated? The following is a practical case, let's take a look.

In PHP, the array_count_values() function is used to count the number of occurrences of all values ​​in an 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.

array_count_values() definition and usage
array_count_values() function is used to count the number of occurrences of all values ​​in an 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.

Syntax
array_count_values(array) Parameter Description
array Required. Specifies the input array.

Example

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

Output:

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

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related matters on the php Chinese website article!

Recommended reading:

in_array() Find whether an array value exists case sharing

Summary of how to use php array search function

The above is the detailed content of The array_count_values() function counts the number of repetitions of array values. 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