如何在foreach
循环内运行此数组并将共享相同的行组合在一起section_id
?
我已经用注释块标记了所有行和部分。
这是数组
Array (
[0] => Array ( // Row 1
[assessment_selection_id] => 63
[assessment_id] => 32
[section_id] => 1 // Section 1
[question_id] => 1
[selection] => 2
[timestamp] => 1368160586
)
[1] => Array ( // Row 2
[assessment_selection_id] => 61
[assessment_id] => 32
[section_id] => 2 // Section 2
[question_id] => 1
[selection] => 3
[timestamp] => 1368160510
)
[2] => Array ( // Row 3
[assessment_selection_id] => 61
[assessment_id] => 32
[section_id] => 2 // Section 2
[question_id] => 1
[selection] => 3
[timestamp] => 1368160510
)
[3] => Array ( // Row 4
[assessment_selection_id] => 61
[assessment_id] => 32
[section_id] => 2 // Section 2
[question_id] => 1
[selection] => 3
[timestamp] => 1368160510
)
)
预期结果
Array (
[0] => Array ( // Section 1
[0] => Array ( // Row 1
[assessment_selection_id] => 63
[assessment_id] => 32
[section_id] => 1
[question_id] => 1
[selection] => 2
[timestamp] => 1368160586
)
)
[1] => Array ( // Section 2
[0] => Array ( // Row 1
[assessment_selection_id] => 61
[assessment_id] => 32
[section_id] => 2
[question_id] => 1
[selection] => 2
[timestamp] => 1368160586
)
[1] => Array ( // Row 2
[assessment_selection_id] => 61
[assessment_id] => 32
[section_id] => 2
[question_id] => 1
[selection] => 2
[timestamp] => 1368160586
)
[2] => Array ( // Row 3
[assessment_selection_id] => 61
[assessment_id] => 32
[section_id] => 2
[question_id] => 1
[selection] => 2
[timestamp] => 1368160586
)
)
)
没有数组的预期结果
第 1 节
第 1 行
Assessment_selection_id、assessment_id、section_id、question_id、选择、时间戳
第 2 节
第 1 行
Assessment_selection_id、assessment_id、section_id、question_id、选择、时间戳
第 2 行
Assessment_selection_id、assessment_id、section_id、question_id、选择、时间戳
第 3 行
Assessment_selection_id、assessment_id、section_id、question_id、选择、时间戳