如何使用php对此测试进行评分?我需要一个百分比...在php中使用加权平均数进行评分
我有一系列的问题,包含正确/不正确的布尔和相应的重量。
我需要先找到正确答案的平均值吗?
方程是什么?
$questions = array(
0=>array(
'Question'=>"Some Question",
'Correct'=>true,
'Weight'=>5,
),
1=>array(
'Question'=>"Some Question",
'Correct'=>false,
'Weight'=>5,
),
2=>array(
'Question'=>"Some Question",
'Correct'=>true,
'Weight'=>4,
),
3=>array(
'Question'=>"Some Question",
'Correct'=>true,
'Weight'=>0,
),
4=>array(
'Question'=>"Some Question",
'Correct'=>false,
'Weight'=>5,
),
5=>array(
'Question'=>"Some Question",
'Correct'=>true,
'Weight'=>4,
),
);
$weights = array(
0=>0
1=>0
2=>.05
3=>.20
4=>.25
5=>.50
);
$totalQuestions=0;
$correctAnswers=0;
$points=0;
foreach($questions as $question){
$totalQuestions++;
if($question['Correct']){
$correctAnswers++;
$points = $points = $weights[$question['Weight'];
}
}