This article mainly introduces the php code for calculating the number of occurrences of the same array value. For more information, see
This article mainly introduces the php code for calculating the number of occurrences of the same array value. For more information, see
Php calculates the number of occurrences of the same array value. You can use the php built-in function array_count_values.
:
Description
Array array_count_values (array $ input) array_count_values () returns an array using the value in the input array as the key name, and the number of times this value appears in the input array as the value.
Array_count_values () Example
The Code is as follows:
<? Php
$ Array = array (1, "hello", 1, "world", "hello ");
Print_r (array_count_values ($ array ));
?>
The above routine will output:
The Code is as follows:
Array
(
[1] => 2
[Hello] => 2
[World] => 1
)