我試圖確定正確回答的問題並正確回答問題。如果回答正確,則顯示「完全正確」,如果不正確則顯示「不正確」信息。問題無論是否正確,總是顯示該問題的答案不正確。它只顯示一條消息,而不是選擇正確的消息來顯示
下面是代碼:
$check = true;
foreach ($studentData['questions'] as $questionId => $questionData) {
if($questionData['answer'] == $questionData['studentanswer'])
{
echo '<td width="30%" class="studentanswer green"><strong>'.htmlspecialchars($questionData['studentanswer']).'</strong></td>' . PHP_EOL;
}
else
{
echo '<td width="30%" class="studentanswer red"><strong>'.htmlspecialchars($questionData['studentanswer']).'</strong></td>' . PHP_EOL;
$check = false;
}
if($check)
{
echo '<p class="green"><strong>Fully Correct</strong></p>';
}
else
{
echo '<p class="red"><strong>Not Correct/Not Fully Correct</strong></p>';
}
}
定義你的'$檢查後= TRUE;'你的foreach循環中。 – Rikesh 2013-03-08 06:02:15