实际上,我正在生成一份报告并打印出该问题ID下的答案。就像13377问题id的回答3次所以我想在下面回应他们的答案和其他问题ID相同。所有数据都是动态的。获得将成为表头的唯一问题ID,该ID的所有答案都将在下面。它就像数据透视表报告。所以我不知道如何做到这一点。
Array
(
[0] => Array
(
[question_id] => 13377
[add_more_counter] => 0
[front_title] => Text question
[value] => first time fill
)
[1] => Array
(
[question_id] => 13377
[add_more_counter] => 0
[front_title] => Text question
[value] => second time fill
)
[2] => Array
(
[question_id] => 13377
[add_more_counter] => 0
[front_title] => Text question
[value] => text question 1
)
[3] => Array
(
[question_id] => 13378
[add_more_counter] => 0
[front_title] => Text box 2
[value] => text question 2
)
)
我想转换成这个
<table border="1"><tbody><tr><th>13377</th><th>13378</th></tr><tr><td>firt time fill</td><td></td></tr><tr><td>second time fill</td><td></td></tr><tr><td>text question 1</td><td></td></tr><tr><td></td><td>text question 2</td></tr></tbody></table>
请帮忙。提前谢谢。
答案 0 :(得分:1)
你需要迭代密钥保持索引不变,
$a = []// Your array
// considering all array have same keys
$keys = array_keys($a[0]);
echo "<table>";
foreach ($keys as $value) {
echo "<tr>";
foreach ($a as $k => $v) {
echo "<td>".$a[$k][$value]."</td>";
}
echo "</tr>";
}
echo "</table>";