以分级阵列为起点。由于它应该包含所有键(对于所有问题),您可以使用它们来检测提交数组中缺少的键并找到所有答案。如果您要手动计算报告,下面是一个示例:
$submission = array(1 => true, 3 => false, 4 => true, 100 => true);
$grading = array(0 => true, 1 => true, 2 => true, 3 => true, 4 => true);
//gather data
$answered = array();
$missing = array();
$correct = array();
$wrong = array();
foreach ($grading as $key => $answer) {
if(array_key_exists($key, $submission)) {
array_push($answered, $key);
if ($submission[$key] === $answer)
array_push($correct, $key);
else
array_push($wrong, $key);
}
else
array_push($missing, $key);
}
//print report
echo "correct\n";
print_r($correct);
echo "\n\n";
echo "wrong\n";
print_r($wrong);
echo "\n\n";
echo "missing\n";
print_r($missing);
echo "\n\n";
echo "% answered\n";
echo 100*(count($answered)/count($grading));
echo "\n\n";
echo "% correct (of all questions)\n";
echo 100*(count($correct)/count($grading));
echo "\n\n";
echo "% correct (of all answered)\n";
echo 100*(count($correct)/count($answered));
echo "\n\n";
echo "% wrong (of all questions)\n";
echo 100*(count($wrong)/count($grading));
echo "\n\n";
echo "% wrong (of all answered)\n";
echo 100*(count($wrong)/count($answered));