开发者

PHP: count how many times a number appears in an array?

I'm running a loop basically that will make an array that contains a million numbers between 1 and 10, how do I开发者_开发知识库 iterate through it and count how many of each there are?

Like:

1 - 201491 times  
2 - 23091 times


There's a native PHP function for that:

$count = array_count_values($array);
print_r($count);

will output:

Array
(
    [1] => 2
    [hello] => 2
    [world] => 1
)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜