大家好,又见面了,我是你们的朋友全栈君。
$data =array('a','b','b','d','f','a','b');
$res=array();
foreach ($data as $key => $value) {
$res[$value]=1;
}//Array ( [a] => 1 [b] => 1 [d] => 1 [f] => 1 )
for($i=0;$i<count($data);$i++)
{
if($res[$data[$i]]==1)
{
for($j=$i+1;$j<count($data);$j++)
{
if($data[$j]==$data[$i])
{
$res[$data[$i]]+=1;
}
}
}
}
/*Array
(
[a] => 2
[b] => 3
[d] => 1
[f] => 1
)*/
arsort($res);
foreach ($res as $key => $value) {
$desc[]=$key;
}
print_r($desc);
/*Array
(
[0] => b
[1] => a
[2] => f
[3] => d
)*/
$a=array("A","Cat","Dog","A","Dog");
print_r(array_count_values($a));
Array
(
[A] => 2
[Cat] => 1
[Dog] => 2
)
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/105904.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...