1 回答
TA贡献1847条经验 获得超7个赞
$wrong = 0;在前循环中!因此,在每次迭代之后,它再次使其为0。
您的代码应如下所示:
$wrong = 0;
foreach($all_files as $file) {
$each_file = file_get_contents($file);
$choosen_answer = substr($each_file, -1); // last number is the number user has choosen
$correct_answer = substr($each_file, 0,1); // first number is the correct answer
// output the answers
echo '<span class="choosen_answer">'.$choosen_answer.'</span>';
echo '<span class="correct_answer">'.$correct_answer.'</span>';
if($choosen_answer != $correct_answer) { // compare the 2 values
$wrong++;
echo '<span class="wrong text-danger">Wrong</span>';
}
else {
echo '<span class="correct text-success">Correct</span>';
}
}
echo $wrong;
- 1 回答
- 0 关注
- 90 浏览
添加回答
举报