$answers = array("a", "b", "c", "a", "a", "a");
$S1Q1 = $_POST['S1Q1'];
$S1Q2 = $_POST['S1Q2'];
$S2Q1 = $_POST['S2Q1'];
$S2Q2 = $_POST['S2Q2'];
$S2Q3 = $_POST['S2Q3'];
$S2Q4 = $_POST['S2Q4'];
$totalValue .= "About OM | Question 01: " . $S1Q1 . " " . ($S1Q1 == $correct[0]) ? 'Correct' : 'Wrong' . "\n";
$totalValue .= " | Question 02: " . $S1Q2 . " " . ($S1Q2 == $correct[1]) ? 'Correct' : 'Wrong' . "\n\n";
$totalValue .= "About EHS | Question 01: " . $S2Q1 . " " . ($S2Q1 == $answers[2]) ? 'Correct' : 'Wrong' . "\n";
$totalValue .= " | Question 02: " . $S2Q2 . " " . ($S2Q2 == $answers[3]) ? 'Correct' : 'Wrong' . "\n";
$totalValue .= " | Question 03: " . $S2Q3 . " " . ($S2Q2 == $answers[4]) ? 'Correct' : 'Wrong' . "\n";
$totalValue .= " | Question 04: " . $S2Q4 . " " . ($S2Q2 == $answers[5]) ? 'Correct' : 'Wrong' . "\n\n";
上記のphpスクリプトがありますが、ループ内のユーザーの正解数と不正解数を計算してパーセンテージを計算するために使用できるメソッドまたは関数は何ですか?
例:
正しい:4
間違っている:2
合計:6
正しいパーセンテージ:((4/6)* 100)= 66.666666666%=> 66%に丸める