zoukankan      html  css  js  c++  java
  • php 统计一维数组中重复的元素个数

    <?php
    echo "<pre>";
    $array = array(1, 1, 1, 54, 3,4, 3,4, 3, 14, 3,4, 3,7,8,9,12,45,66,5,7,8,9,2,45);
    
    $a =0;
    foreach ($array as $str) {
        @$result[$str] = $result[$str] + 1;
        $a = $a + 1;
    }
    echo $a;
    print_r($result);
    25Array
    (
        [1] => 3
        [54] => 1
        [3] => 5
        [4] => 3
        [14] => 1
        [7] => 2
        [8] => 2
        [9] => 2
        [12] => 1
        [45] => 2
        [66] => 1
        [5] => 1
        [2] => 1
    )
    <?php
    echo "<pre>";
    $array = array(1, 1, 1, 54, 3,4, 3,4, 3, 14, 3,4, 3,7,8,9,12,45,66,5,7,8,9,2,45);
    
    
    foreach ($array as $str) {
        
        @$result[$str] = $result[$str] + 1;
        //$result[1] = 0 + 1;
        //$result[1] = 1 + 1;
        //$result[1] = 2 + 1;
        //$result[54] = 0 + 1;
        //$result[3] = 0 + 1;
    
    }
    
    print_r($result);
  • 相关阅读:
    加载声音的过程
    onkeyup,onkeydown和onkeypress
    加载着色器的异常

    3
    1
    1
    java总结
    环路
    own address as source address
  • 原文地址:https://www.cnblogs.com/hellowzd/p/6588942.html
Copyright © 2011-2022 走看看