PHP如何统计里面相同的数组的值?
$arr=array(array('fid'=>1),array('fid'=>1),array('fid'=>2),array('fid'=>2),array('fid...
$arr = array(
array('fid' => 1),
array('fid' => 1),
array('fid' => 2),
array('fid' => 2),
array('fid' => 4),
array('fid' => 4),
array('fid' => 5));
print_r ( array_count_values ( $arr));
array_count_values 不起作用啊 展开
array('fid' => 1),
array('fid' => 1),
array('fid' => 2),
array('fid' => 2),
array('fid' => 4),
array('fid' => 4),
array('fid' => 5));
print_r ( array_count_values ( $arr));
array_count_values 不起作用啊 展开
1个回答
推荐于2017-12-16
展开全部
这个函数不支持2维数组,需要处理一下
<?php
$arr = array(
array('fid' => 1),
array('fid' => 1),
array('fid' => 2),
array('fid' => 2),
array('fid' => 4),
array('fid' => 4),
array('fid' => 5)
);
// www.hi-docs.com/php/array_column.html
$arr = array_column($arr,'fid');
print_r ( array_count_values ( $arr));
?>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |