正しく答えられた質問と間違って答えられた質問を判断しようとしています。正解の場合は「完全に正解」を表示し、不正解の場合は「不正解」のメッセージを表示します。問題は正しいかどうかに関係なく、質問の回答が間違っていることが常に表示されます。
以下はコードです:
$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>';
}
}