PHP 统计数组中所有的值出现的次数 array_count_values 函数

array_count_values() 函数用于统计数组中所有的值出现的次数。

array_count_values()

PHP array_count_values() 函数用于统计数组中所有的值出现的次数,返回一个数组,其元素的键名是原数组的值,键值是该值在原数组中出现的次数。

语法:

1
array array_count_values array array )

例子:

1
2
3
4
<?php
$arr_a array ( "a" "b" "a" , 1);
print_r( array_count_values ( $arr_a ));
?>

输出:

1
2
3
4
5
6
Array
(
     [a] => 2
     [b] => 1
     [1] => 1
)

 

猜你喜欢

转载自www.cnblogs.com/todarcy/p/10984130.html