array_count_values
統計數組中各個的值的個數
array_count_values()
函數對數組中的所有值進行計數。
array_count_values()
函數用於統計數組中所有值出現的次數。
本函數返回一個數組,其元素的鍵名是原數組的值,鍵值是該值在原數組中出現的次數。
對數組中的所有值進行計數:
<?php $a = array ( "A" , "Cat" , "Dog" , "A" , "Dog" ) ; print_r ( array_count_values ( $a ) ) ; ?>
親自試一試
array_count_values ( array )
參數 | 描述 |
---|---|
array | 必需。規定需要對值進行計數的數組。 |