Jump to content

[SOLVED] Marking a test


maxudaskin

Recommended Posts

I have an online test that uses radio groups. I have an answer key as an array and I wanted to use arrays to mark it... can you either tell me a better way to do it or help me complete this simple part of it...

 

<?php
$test_key   = array("c","b","a","d","d","c","c","b","d","a");
$given_ans  = array($_POST['q1'],$_POST['q2'],$_POST['q3'],$_POST['q4'],$_POST['q5'],$_POST['q6'],$_POST['q7'],$_POST['q8'],$_POST['q9'],$_POST['q10']);
?>

Link to comment
https://forums.phpfreaks.com/topic/105095-solved-marking-a-test/
Share on other sites

<?php
$test_key   = array("c","b","a","d","d","c","c","b","d","a");
$given_ans  = array($_POST['q1'],$_POST['q2'],$_POST['q3'],$_POST['q4'],$_POST['q5'],$_POST['q6'],$_POST['q7'],$_POST['q8'],$_POST['q9'],$_POST['q10']);
foreach ($given_ans as $k=>$v) {
   if ($v == $test_key[$k]) {
        $ans[] = 1;
   }
   else {
         $ans[] = 2;
   }
}

foreach ($ans as $k=>$v) {
   $num = $k+1;
   $response = ($v==1)?"Correct":"Incorrect";
   echo $num . ": " . $response;
}
?>

<?php
$test_key   = array("c","b","a","d","d","c","c","b","d","a");
$given_ans  = array($_POST['q1'],$_POST['q2'],$_POST['q3'],$_POST['q4'],$_POST['q5'],$_POST['q6'],$_POST['q7'],$_POST['q8'],$_POST['q9'],$_POST['q10']);
foreach ($given_ans as $k=>$v) {
   if ($v == $test_key[$k]) {
        $mark += 1;
   }
   else {
         $mark += 0;
   }
}
echo $mark;


?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.