開始点としてgrading-arrayを取ります。(すべての質問に対して)すべてのキーが含まれている必要があるため、それらを使用して、submission-arrayで欠落しているキーを検出し、すべての回答を見つけることができます。レポートを手動で計算する場合の例を次に示します。
$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));