1

我正在尝试确定正确回答的问题和错误回答的问题。如果回答正确,则显示“完全正确”,否则如果不正确,则显示“不正确”消息。问题是无论是否正确,它总是显示该问题的回答不正确。

下面是代码:

    $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>';
}

}
4

1 回答 1

1

在此行之后再次设置true$check

if($questionData['answer'] == $questionData['studentanswer'])
{
echo '<td width="30%" class="studentanswer green"><strong>'.htmlspecialchars($questionData['studentanswer']).'</strong></td>' . PHP_EOL;
$check = true;
} else
于 2013-03-08T06:00:42.320 回答