I have an array of date, something like below
Array
(
[0] => stdClass Object
(
[question_id] => 64
[title] => Question1
[question_type_id] => 1
[settings] =>
[poll_id] => 5
[answer] => Array
(
[0] => stdClass Object
(
[answer_id] => 1
[poll_id] => 5
[question_id] => 64
[answer] => Answer1-1
[created_at] => 2018-07-08 17:36:15
)
[1] => stdClass Object
(
[answer_id] => 5
[poll_id] => 5
[question_id] => 64
[answer] => Answer1-2
[created_at] => 2018-07-08 19:27:33
)
)
)
[1] => stdClass Object
(
[question_id] => 65
[title] => Question2
[question_type_id] => 6
[settings] => ["više od 2km","manje od 2km"]
[poll_id] => 5
[answer] => Array
(
[0] => stdClass Object
(
[answer_id] => 2
[poll_id] => 5
[question_id] => 65
[answer] => Answer2-1
[created_at] => 2018-07-08 17:36:47
)
[1] => stdClass Object
(
[answer_id] => 6
[poll_id] => 5
[question_id] => 65
[answer] => Answer2-2
[created_at] => 2018-07-09 23:31:31
)
)
)
I need a table in browser to look like enter image description here
Question1 Question2 Question3
Answer1-1 Answer2-1 Answer3-1
Answer1-2 Answer2-2 Answer3-2
This is my code:
<table class="table">
<thead>
<tr>
<?php foreach ($DATA['question'] as $question): ?>
<th><?php echo htmlspecialchars($question->title); ?></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<tr>
<?php foreach ($DATA['question'] as $question): ?>
<td><?php for ($i=0,$j=count((array)$question->answer);$i<$j;$i++) {
echo htmlspecialchars($question->answer[$i]->answer);
}?></td>
<?php endforeach; ?>
</tr>
</tbody>
My problem is that I can not place Answer1-2 in the next row of table. Any idea? Thanks a lot