php中的多个迭代器

时间:2015-07-07 02:55:37

标签: php iteration

我有以下代码。基本上,对于每个问题,如果答案是" question_id"匹配问题的ID我需要它列出问题的所有可能答案。它针对第一个问题执行此操作,但随后退出循环。

            <?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>&nbsp;&nbsp;&nbsp;<?php echo $answer['answer']; ?></td>
                </tr>
                <?php } ?>
                <?php endforeach ?>
            <?php endforeach; ?>
            </tr>

如何继续浏览$ question [&#39; id&#39;]值的其余部分?

1 个答案:

答案 0 :(得分:1)

这基本上是因为你错过了结束分号

<?php endforeach ?> // <-- here

如果您正确设置error reporting,那么应该会给您一个致命的错误。