PHP array_count_values

 array_count_values ​​is used to count the number of elements in the array ( Array ). When you put an array in array_count_values, the system will use the elements of the array as a new key and return a new Array containing the new key and key The key value is the number of occurrences in the original array. Although it is a bit abstract, it is easier to understand by looking at the following example.


PHP array_count_values ​​syntax example

array_count_values ​​(array input array to be queried)


PHP array_count_values ​​implementation example
<?php
$Arr=array( "1" , "A" ,"1" ,"B" );
print_r(array_count_values($Arr)); // 輸出結果 Array ( [1] => 2 [A] => 1 [B] => 1 )
?>
In the example, a simple one-dimensional array is prepared. There are four elements, and the repeated element is 1, so when we put $Arr in array_count_values ​​to process, we can see that PHP outputs a new array, key Is the array element of the original $Arr, and the key value is the statistical number of the element in the original $Arr.

Post a Comment

0 Comments