$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