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