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
)
精彩评论