Home > Backend Development > PHP Tutorial > PHP code to count the number of occurrences of the same value in an array (array_count_values), arraycountvalues_PHP tutorial

PHP code to count the number of occurrences of the same value in an array (array_count_values), arraycountvalues_PHP tutorial

WBOY
Release: 2016-07-13 10:09:25
Original
1057 people have browsed it

php code for counting the number of occurrences of the same value in an array (array_count_values), arraycountvalues

php counts the number of occurrences of the same value in an array. You can use php’s own function array_count_values
:
Description

array array_count_values ​​( array $input )array_count_values() returns an array that uses the value in the input array as the key name and the number of times the value appears in the input array as the value.

array_count_values() example

Copy code The code is as follows:

$array = array(1, "hello", 1, "world", "hello");
print_r(array_count_values ​​($array));
?>

The above routine will output:

Copy code The code is as follows:

Array
(
[1] => 2
[hello] => 2
[world] => 1
)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/945713.htmlTechArticlephp code for counting the number of occurrences of the same value in an array (array_count_values), arraycountvalues ​​php counts the number of occurrences of the same value in an array, you can use PHP comes with the function array_count_values: Description...
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