foreach ($studentData['questions'] as $questionId => $questionData) {
echo '<h3>'.$questionData['questionno'].': '.$questionData['content'].'</h3>';
}
上面的代码可以显示例如3个问题:遇到问题使用count
- 什么是2 + 2?
- 什么是3 + 3?
- 什么是4 + 4?
现在我想要做的就是进行计数,以确定有多少问题存在,所以我做了下面的代码:
foreach ($studentData['questions'] as $questionId => $questionData) {
$noofquestions = count($questionData['questionno']);
echo '<h3>'.$questionData['questionno'].': '.$questionData['content'].'</h3>';
}
但问题是,而不是为$noofquestions
输出3
是输出1
。为什么是这样?
而且我想执行如何可能时间Fully Correct
显示为$noofcorrect
和seperately计数多少次Not Correct/Not Fully Correct
显示,但不知道如何用这个代码确定此低于:
<?php
if($check)
{
echo '<p class="green"><strong>Fully Correct</strong></p>';
}
else
{
echo '<p class="red"><strong>Not Correct/Not Fully Correct</strong></p>';
}
http://php.net/count – hakre 2013-03-08 05:42:57
重新检查所有的变量名。重新阅读foreach语法文档。我们可以看到$ studentData中有三个项目,但是您正在计数$ questionData。 – 2014-04-19 13:10:54