jeudi 23 mars 2017

Differentiation Choices in Multiple choice with Multiple Answer Using PHP

Hiii Everyone,

I have Multiple Choices With Multiple Answer.I Want to different options with correct answer as well as wrong answer.I had already done this type of question with single answer but in this case correct answer may be more than one. Differentiate Choices with Correct Answer using PHP. I had tried like below code but I will get for only single value check not for all.I dont know why

<?php 
$a1 = [trim($m_o1), trim($m_o2), trim($m_o3), trim($m_o4), trim($m_o5)];
shuffle($a1);
$b1      = ['m_o1', 'm_o2', 'm_o3', 'm_o4' ,'m_o5'];
$result1 = array_combine($b1, $a1);
extract($result1);
$sc_flag2=0;
$actual_flag2=0;
if($m_c1=='1')
{
    $correct_answer2 = array(
        $m_oo1
    );

}
else if($m_c1=='2')
{
    $correct_answer2 = array(
        $m_oo1,
        $m_oo2
    );

}
else if($m_c1=='3')
{
    $correct_answer2 = array(
        $m_oo1,
        $m_oo2,
        $m_oo3
    );

}
else if($m_c1=='4')
{
    $correct_answer2 = array(
        $m_oo1,
        $m_oo2,
        $m_oo3,
        $m_oo4
    );

}
else if($m_c1=='5')
{
$correct_answer2 = array(
        $m_oo1,
        $m_oo2,
        $m_oo3,
        $m_oo4,
        $m_oo5
    );

}
else
{
    $correct_answer2 = array();

}

$multiple_answer = array(
        $multiple_answer_1_1,
        $multiple_answer_1_2,
        $multiple_answer_1_3,
        $multiple_answer_1_4,
        $multiple_answer_1_5
    );
//print_r($multiple_answer);
//print_r($correct_answer2);

if (in_array($m_o1, $correct_answer2) && in_array($multiple_answer, $correct_answer2)) {
    $sc_flag2 = 1; // student's selected correct flag
}
if (in_array($m_o2, $correct_answer2) && in_array($multiple_answer, $correct_answer2)) {
    $sc_flag2 = 2; // student's selected correct flag
}
if (in_array($m_o3, $correct_answer2) && in_array($multiple_answer, $correct_answer2)) {
    $sc_flag2 = 3; // student's selected correct flag
}
if (in_array($m_o4, $correct_answer2) && in_array($multiple_answer, $correct_answer2)) {
    $sc_flag2 = 4; // student's selected correct flag
}
if (in_array($m_o5, $correct_answer2) && in_array($multiple_answer, $correct_answer2)) {
    $sc_flag2 = 5; // student's selected correct flag
}

if (in_array($m_o1, $correct_answer2)) {
    $correct_flag2 = 1; // student's selected correct flag
}
if (in_array($m_o2, $correct_answer2)) {
    $correct_flag2 = 2; // student's selected correct flag
}
if (in_array($m_o3, $correct_answer2)) {
    $correct_flag = 3; // student's selected correct flag
}
if (in_array($m_o4, $correct_answer2)) {
    $correct_flag2 = 4; // student's selected correct flag
}
if (in_array($m_o5, $correct_answer2)) {
    $correct_flag2 = 5; // student's selected correct flag
}
if (in_array($m_o1, $multiple_answer)) {
    $actual_flag2 = 1; // student's selected correct flag
}
if (in_array($m_o2, $multiple_answer)) {
    $actual_flag2 = 2; // student's selected correct flag
}
if (in_array($m_o3, $multiple_answer)) {
    $actual_flag2 = 3; // student's selected correct flag
}
if (in_array($m_o4, $multiple_answer)) {
    $actual_flag2 = 4; // student's selected correct flag
}
if (in_array($m_o5, $multiple_answer)) {
    $actual_flag2 = 5; // student's selected correct flag
}
?>
<?php if ($sc_flag2 == 1) { // correct answer by student green// see for correct option I had added green border and bg but tht time alps yello bg oisk showingokok ?>
    <label style="font-size:14px;background-color:#90EE90;border:1px solid green;padding:10px" >
        <label class="review-icon"><i class="fa fa-fw fa-check-circle-o" style="color:green;font-size:15px"></i></label>
        <span class="">(A) <?php echo $m_o1; ?>
    </label>
<?php } else if ($actual_flag2 == 1 && $correct_flag2 != 1) { // student's answer is wrong here and student answer is given red
    ?>
    <label style="font-size:14px;background-color:lightgray;border:1px solid red;padding:10px" >
        <label class="review-icon"><i class="fa fa-fw fa-times" style="color:red;font-size:15px"></i></label>
        <span class="">(A) <?php echo $m_o1; ?>
    </label>
<?php } else if ($correct_flag2 == 1) { // student have not given answer and correct option will be yellow ?>
    <label style="font-size:14px;background-color:yellow;border:1px solid yellow;padding:10px" >
        <label class="review-icon"><i class="fa fa-fw fa-check-circle-o" style="color:green;font-size:15px"></i></label>
        <span class="">(A) <?php echo $m_o1; ?>
    </label>
<?php } else {?>
    <label style="font-size:14px">
        <span class=""><input type="checkbox" value="<?php echo $m_o1; ?>" ></span> (A) <?php echo $m_o1; ?>
    </label>
<?php }?><br/><br/>
<?php if ($sc_flag2 == 2) {?>
    <label style="font-size:14px;background-color:#90EE90;border:1px solid green;padding:10px" >
        <label class="review-icon"><i class="fa fa-fw fa-check-circle-o" style="color:green;font-size:15px"></i></label>
        <span class="">(B) <?php echo $m_o2; ?>
    </label>
<?php } else if ($actual_flag2 == 2 && $correct_flag2 != 2) {
    ?>
    <label style="font-size:14px;background-color:lightgray;border:1px solid red;padding:10px" >
        <label class="review-icon"><i class="fa fa-fw fa-times" style="color:red;font-size:15px"></i></label>
        <span class="">(B) <?php echo $m_o2; ?>
    </label>
<?php } else if ($correct_flag2 == 2) {?>
    <label style="font-size:14px;background-color:yellow;border:1px solid yellow;padding:10px" >
        <label class="review-icon"><i class="fa fa-fw fa-check-circle-o" style="color:green;font-size:15px"></i></label>
        <span class="">(B) <?php echo $m_o2; ?>
    </label>
<?php } else {?>
    <label style="font-size:14px">
        <span class=""><input type="checkbox" value="<?php echo $m_o2; ?>" ></span> (B) <?php echo $m_o2; ?>
    </label>
<?php }?><br/><br/>
<?php if ($sc_flag2 == 3) {?>
    <label style="font-size:14px;background-color:#90EE90;border:1px solid green;padding:10px" >
        <label class="review-icon"><i class="fa fa-fw fa-check-circle-o" style="color:green;font-size:15px"></i></label>
        <span class="">(C) <?php echo $m_o3; ?>
    </label>
<?php } else if ($actual_flag2 == 3 && $correct_flag2 != 3) {
    ?>
    <label style="font-size:14px;background-color:lightgray;border:1px solid red;padding:10px" >
        <label class="review-icon"><i class="fa fa-fw fa-times" style="color:red;font-size:15px"></i></label>
        <span class="">(C) <?php echo $m_o3; ?>
    </label>
<?php } else if ($correct_flag2 == 3) {?>
    <label style="font-size:14px;background-color:yellow;border:1px solid yellow;padding:10px" >
        <label class="review-icon"><i class="fa fa-fw fa-check-circle-o" style="color:green;font-size:15px"></i></label>
        <span class="">(C) <?php echo $m_o3; ?>
    </label>
<?php } else {?>
    <label style="font-size:14px">
        <span class=""><input type="checkbox" value="<?php echo $m_o3; ?>" ></span> (C) <?php echo $m_o3; ?>
    </label>
<?php }?><br/><br/>
<?php if ($sc_flag2 == 4) {?>
    <label style="font-size:14px;background-color:#90EE90;border:1px solid green;padding:10px" >
        <label class="review-icon"><i class="fa fa-fw fa-check-circle-o" style="color:green;font-size:15px"></i></label>
        <span class="">(D) <?php echo $m_o4; ?>
    </label>
<?php } else if ($actual_flag2 == 4 && $correct_flag2 != 4) {
    ?>
    <label style="font-size:14px;background-color:lightgray;border:1px solid red;padding:10px" >
        <label class="review-icon"><i class="fa fa-fw fa-times" style="color:red;font-size:15px"></i></label>
        <span class="">(D) <?php echo $m_o4; ?>
    </label>
<?php } else if ($correct_flag2 == 4) {?>
    <label style="font-size:14px;background-color:yellow;border:1px solid yellow;padding:10px" >
        <label class="review-icon"><i class="fa fa-fw fa-check-circle-o" style="color:green;font-size:15px"></i></label>
        <span class="">(D) <?php echo $m_o4; ?>
    </label>
<?php } else {?>
    <label style="font-size:14px">
        <span class=""><input type="checkbox" value="<?php echo $m_o4; ?>" ></span> (D) <?php echo $m_o4; ?>
    </label>
<?php }?><br/><br/>
<?php if ($sc_flag2 == 5) {?>
    <label style="font-size:14px;background-color:#90EE90;border:1px solid green;padding:10px" >
        <label class="review-icon"><i class="fa fa-fw fa-check-circle-o" style="color:green;font-size:15px"></i></label>
        <span class="">(E) <?php echo $m_o5; ?>
    </label>
<?php } else if ($actual_flag2 == 5 && $correct_flag2 != 5) {
    ?>
    <label style="font-size:14px;background-color:lightgray;border:1px solid red;padding:10px" >
        <label class="review-icon"><i class="fa fa-fw fa-times" style="color:red;font-size:15px"></i></label>
        <span class="">(E) <?php echo $m_o5; ?>
    </label>
<?php } else if ($correct_flag2 == 5) {?>
    <label style="font-size:14px;background-color:yellow;border:1px solid yellow;padding:10px" >
        <label class="review-icon"><i class="fa fa-fw fa-check-circle-o" style="color:green;font-size:15px"></i></label>
        <span class="">(E) <?php echo $m_o5; ?>
    </label>
<?php } else {?>
    <label style="font-size:14px">
        <span class=""><input type="checkbox" value="<?php echo $m_o5; ?>" ></span> (D) <?php echo $m_o5; ?>
    </label>
<?php }?><br/><br/>

My array values are

 for $a1=which means list of options like

        Array ( [0] => Larger animals in the same territory may vacate their burrows for meerkats to stay in them. [1] => The organised lifestyle and the peculiar body structures help meerkats live a comfortable life in extremities. [2] => Territorial fights are usually organised to solve disputes about all problems. [3] => Meerkats show strong solidarity with their group members for the sake of their safety and comfort. [4] => Meerkats dig their burrows in a unique way, having around 15 entrance and exit holes. )

Answers given by student where we need to compare this options

$multiple_answers= Array ( [0] => Larger animals in the same territory may vacate their burrows for meerkats to stay in them. [1] => Meerkats dig their burrows in a unique way, having around 15 entrance and exit holes. [2] => undefined [3] => undefined [4] => undefined )

And my correct answer2=Array ( [0] => Meerkats show strong solidarity with their group members for the sake of their safety and comfort. [1] => The organised lifestyle and the peculiar body structures help meerkats live a comfortable life in extremities. )

Here I want the result with

[0] => Larger animals in the same territory may vacate their burrows for meerkats to stay in them. [1] => Meerkats dig their burrows in a unique way, having around 15 entrance and exit holes.This two option value with red. And the options with [0] => Meerkats show strong solidarity with their group members for the sake of their safety and comfort. [1] => The organised lifestyle and the peculiar body structures help meerkats live a comfortable life in extremities.With yellow.But Im getting output with wrong Answer.Please check my code and let me know what are the mistakes ?Plese anyone help me to get out of this issue.Thanks in advance.Thank u somuch.




Aucun commentaire:

Enregistrer un commentaire