摘要:php计算数组相同值出现次数,可以使用php自带函数array_count_values:说明array array_count_values ( array $input )array_count_values() 返回一个数组,该数组用 input 数组中的值作为键名,该值在 input 数组中出现的次数作为值。array_count_values() 例子<?php $array&nb
php计算数组相同值出现次数,可以使用php自带函数array_count_values
:
说明
array array_count_values ( array $input )array_count_values() 返回一个数组,该数组用 input 数组中的值作为键名,该值在 input 数组中出现的次数作为值。
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计算数组相同值出现次数的代码(array_count_values)请关注PHP中文网(www.php.cn)其他文章!