赞
踩
在PHP中,数组函数 array_count_values() 用于统计数组中所有的值。
函数语法:
array_count_values ( array $array ) : array
函数参数说明:
参数 | 描述 |
---|---|
array | 必需。规定需要统计数组中所有值出现次数的数组。 |
array_count_values() 函数统计数组中所有的值,返回一个关联数组,用 array 数组中的值作为键名,该值在数组中出现的次数作为值。
举例1,统计数组中所有的值:
<?php // 定义数组 $arr = ['hello', 'world', 'hello', 'china']; // 统计数组的值 $res = array_count_values($arr); // 输出结果数组 var_dump($res);
以上代码输出如下:
array (size=3) 'hello' => int 2 'world' => int 1 'china' => int 1
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。