您的位置:首页 > 其它

统计 数据中 重复值的次数( 另外,可再对其进行排序,重复次数多的在前边

2015-07-09 16:50 423 查看

array_count_values

(PHP 4, PHP 5)
array_count_values —
统计数组中所有的值出现的次数

说明

array
array_count_values ( array
$input
)
array_count_values() 返回一个数组,该数组用
input
数组中的值作为键名,该值在
input
数组中出现的次数作为值。

参数

input

统计这个数组的值

返回值

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

错误/异常

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

范例

Example #1 [b]array_count_values() 例子[/b]

<?php

$array = array(1, "hello", 1, "world", "hello");

print_r(array_count_values($array));

?>


以上例程会输出: (如果在下边基础上再排序的话, 1 1 hello hello .. 这样,键当值 ,值当输出的次数)

Array
(
[1] => 2
[hello] => 2
[world] => 1
)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: