一、统计数组中所有的值
array_count_values() |
参数 | 必须 | 示例 |
需要统计值的数组 | 是 | $a = array(1, "hello", 1, "world", "hello"); |
返回值 | 错误 / 异常 | 注意事项 |
返回一个关联数组, 用参数数组中的值作为键名, 用该键名在参数数组中出现的次数作为值 | 对数组里面的每个不是 string 和 integer 类型的元素抛出一个警告错误(E_WARNING)。 | 对于值是字符串的区分大小写 |
例子1: |
|
返回结果: Array ( [1] => 2 [hello] => 2 [world] => 1 ) |
例子2 : 在多维数组中找到具有特定值的项数的简单方法 |
|
返回结果: 2 |