php - 如何计算数组中项的出现次数

时间:2010-04-27 11:06:52

标签: php arrays

拿这个数组:

Array ( [#twitterwhites] => 0 [#lufc] => 0 [#FOOTBALL] => 0 [#Liverpool] => 0 [#liverpool] => 0 [#ESPN] => 0 [#LUFC] => 0 [#cafc] => 0 [#cafc] => 0 [#ocra] => 0 [#nra] => 0 [#2nd] => 0 [#secondamendment] => 0 [#SCR] => 0 [#TC500] => 0 [#cpfc] => 0 [#MOT] => 0 ) 

我想要返回这样的结果:

#liverpool = 2

#cafc = 2

#LUFC = 1  

ETC ETC

我该怎么做?

1 个答案:

答案 0 :(得分:2)

您可以使用array_count_values()功能,对阵列进行一些修改,因为它只计算,而不是

(正如您对问题的评论中所建议的,无论如何,您不能在数组中多次使用相同的密钥 - 这意味着您的数组可能已经将您的项目作为值,而不是密钥)