如何获取字符串在数组中常见的数量

嘿,我有一堆数据的阵列

我做了一个array_count_values ,现在我有这样的东西:

$bots = array_count_values($all_bots);
arsort($bots); 

Array ( ["abc"] => 9 ["xyz"] => 1 )

我只想得到号码。 所以只是9。

有人能告诉我如何得到这个数字吗?


$bots = array_count_values($all_bots);
arsort($bots)
echo current($bots); 

排序后,您可以使用current()获取第一个值。 但是,我建议放弃排序操作并使用max来代替:

$mostOccuring = max(array_count_values($all_bots));

这可以更有效地产生相同的结果。 显然你不会得到字符串本身(“abc”)。

链接地址: http://www.djcxy.com/p/10183.html

上一篇: how to get number of how much the string is common in a array

下一篇: What does %w(array) mean?