zoukankan      html  css  js  c++  java
  • php函数 array_count_values

     

    (PHP 4, PHP 5, PHP 7)

    array_count_values — 统计数组中所有的值

     

    array_count_values ( array $array ) : array

    array_count_values() 返回一个数组: 数组的键是 array 里单元的值; 数组的值是 array 单元的值出现的次数。

     

    input

    统计这个数组的值

     

    返回一个关联数组,用 array 数组中的值作为键名,该值在数组中出现的次数作为值。

     

    对数组里面的每个不是 string 和 integer 类型的元素抛出一个警告错误(E_WARNING)。

     

    Example #1 array_count_values() 例子

    <?php
    $array = array(1, "hello", 1, "world", "hello");
    print_r(array_count_values($array));
    ?>

    以上例程会输出:

    Array
    (
        [1] => 2
        [hello] => 2
        [world] => 1
    )


    <?php
    /**
    * Created by PhpStorm.
    * User: mac
    * Date: 2019/4/13
    * Time: 10:16
    */

    $arr = [1,2,3,4,5,2,3,4,2,3,4,'a','a','c','age','age'];

    echo "<pre>";
    $res = array_count_values($arr);
    print_r($res);


    输出
    Array
    (
        [1] => 1
        [2] => 3
        [3] => 3
        [4] => 3
        [5] => 1
        [a] => 2
        [c] => 1
        [age] => 2
    )
  • 相关阅读:
    【poj3764】 The xor-longest Path
    【poj3261】 Milk Patterns
    【poj3237】 Tree
    【bzoj2654】 tree
    【poj3122】 Pie
    【poj1011】 Sticks
    【poj1186】 方程的解数
    【poj2741】 Colored Cubes
    【poj3141】 Distant Galaxy
    【bzoj2456】 mode
  • 原文地址:https://www.cnblogs.com/brady-wang/p/10700049.html
Copyright © 2011-2022 走看看