本文介绍了PHP的话阵列数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的阵列

How to get the word and count like

God : 4
Angel : 3
Human : 2
Devil : 1
解决方案

Take a look at array_count_values and arsort.

<?php
$myarray = array("Human","Angel","God","Angel","Devil","God","God","Human","God","Angel");

$result = array_count_values($myarray);
arsort($result);

foreach($result as $word => $count)
{
    echo $word." was found ".$count." time(s)<br/>";
}
?>

这篇关于PHP的话阵列数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 12:37