Array
(
[0] => Array
(
[0] => a
[1] => a
[2] => b
[3] => c
[4] => b
[5] => c
[6] => b
)
)
所以我必须按照计数总数来分组。数组如(输出):
a = 2
b = 3
c = 2
如果数组a
的使用次数是a
的两倍,则2
将为{{1}}。
答案 0 :(得分:5)
使用此:
array_count_values(array)
例如:
<?php
$a=array("Cat","Dog","Horse","Dog");
print_r(array_count_values($a));
?>
输出:
Array ( [Cat] => 1 [Dog] => 2 [Horse] => 1 )
答案 1 :(得分:1)
复制粘贴代码
<?php
$rt=Array(Array('a','a','b','b','c','c'));
$out=array_count_values( $rt[0]);
print_r($out) ;
?>
输出
Array
(
[a] => 2
[b] => 2
[c] => 2
)