首页 > php求数组中每个元素出现的次数

php求数组中每个元素出现的次数

有一个很大的数组 不用自带方法 怎么做呢?


为什么不用PHP的自带函数array_count_values

不用自带方法

    $tagList = array("Cat", "Dog", "Horse", "Dog");
    $count = array();
    foreach ($tagList as $tVal) {
        if (!isset($count[$tVal])) {
            $count[$tVal] = 1;
        } else {
            $count[$tVal]++;
        }

    }
【热门文章】
【热门文章】