首页 > 代码库 > php 统计二维数组中某个相等值的总个数,并且组合成一个新的数组 转发
php 统计二维数组中某个相等值的总个数,并且组合成一个新的数组 转发
$ar
=
array
(
array
(
‘sv_id‘
=> 1,
‘mid‘
=> 1,
‘sv_question1‘
=> 20 ),
array
(
‘sv_id‘
=> 2,
‘mid‘
=> 2,
‘sv_question1‘
=> 10 ),
array
(
‘sv_id‘
=> 3,
‘mid‘
=> 1,
‘sv_question1‘
=> 20 ),
array
(
‘sv_id‘
=> 4,
‘mid‘
=> 3,
‘sv_question1‘
=> 20 ),
array
(
‘sv_id‘
=> 5,
‘mid‘
=> 2,
‘sv_question1‘
=> 20 ),
);
$res
=
array
();
foreach
(
$ar
as
$item
) {
$res
[
$item
[
‘mid‘
]][
$item
[
‘sv_id‘
]] =
$item
;
}
print_r(
$res
);
效果如下
Array
(
[1] => Array
(
[1] => Array
(
[sv_id] => 1
[mid] => 1
[sv_question1] => 20
)
[3] => Array
(
[sv_id] => 3
[mid] => 1
[sv_question1] => 20
)
)
[2] => Array
(
[2] => Array
(
[sv_id] => 2
[mid] => 2
[sv_question1] => 10
)
[5] => Array
(
[sv_id] => 5
[mid] => 2
[sv_question1] => 20
)
)
[3] => Array
(
[4] => Array
(
[sv_id] => 4
[mid] => 3
[sv_question1] => 20
)
)
)
转发
详情见
http://bbs.csdn.net/topics/390590251
php 统计二维数组中某个相等值的总个数,并且组合成一个新的数组 转发
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。