php 统计二维数组中某个相等值的总个数,并且组合成一个新的数组 转发
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 统计二维数组中某个相等值的总个数,并且组合成一个新的数组 转发的主要内容,如果未能解决你的问题,请参考以下文章