php中的多迭代器
我有以下代码。基本上,对于每个问题,如果答案的“问题id”与问题的id匹配,我需要它列出问题的所有可能答案。它对第一个问题执行此操作,但随后退出循环php中的多迭代器,php,iteration,Php,Iteration,我有以下代码。基本上,对于每个问题,如果答案的“问题id”与问题的id匹配,我需要它列出问题的所有可能答案。它对第一个问题执行此操作,但随后退出循环 <?php foreach ($questions as $question) : ?> <tr> <td><?php echo $question['question']; ?></td>
<?php foreach ($questions as $question) : ?>
<tr>
<td><?php echo $question['question']; ?></td>
<td><?php echo $question['id']; ?></td>
</tr>
<?php foreach ($answers as $answer) : ?>
<?php if ($answer['question_id'] == $question['id']) { ?>
<tr>
<td> <?php echo $answer['answer']; ?></td>
</tr>
<?php } ?>
<?php endforeach ?>
<?php endforeach; ?>
</tr>
我如何继续遍历$question['id']值的其余部分?这基本上是因为缺少结束分号
<?php endforeach ?> // <-- here
//可以添加$questions
中的内容吗?它是一个问题对象数组,包含id、问题(实际字符串问题)和调查id,调查id是它们所属调查的id$answers是答案对象的数组(id、answer、question_id)。在我看来,可以为每个数组添加一个示例来测试itLooks的逻辑性。您可能没有按照预期在变量中获得正确的数据。运行$questions和$answers,查看它们是否包含您期望的所有数据。