Compare questions with correct answers

-1

I have the XML of which brings the questions from 1 to 10 with 5 answers each (A, B, C, D, E). The user will list those questions and answer them. Through the system, I can check the correct responses of users as follows:

foreach($xml->avaliacao->questao as $listar => $valor) { 

         if($_POST["respostas"][$c] == $respostas){
            $somar[0] = $cc++;
            $respostasC = $_POST["respostas"][$c];
            $rc[] = $respostasC;
         }else{
            $somarE[0] = $cc++;
            $respostasE = $_POST["respostas"][$c];
            $rr[] = $respostasE;
        }
}

I just forgot to compare that answer to a particular question, considering that the questions are like this in XML:

  

Question 1: A B C D E

     

Question 2: A B C D E

     

Question ...

I would like that when listing the correct answers, they appear as follows:

  

If the user hits:   Question 2: The   Question 5: C   Question 7: D   ......

     

If the user misses:   Question 3   Question 4   Question 6   ......

I hope it was clear in my doubts.

    
asked by anonymous 05.06.2016 / 23:50

1 answer

-2

Colleagues. I got it sorted out. Here's who you need:

foreach($xml->avaliacao->questao as $listar => $valor) { 

         if($_POST["respostas"][$c] == $respostas){
            $somar[0] = $cc++;
            $respostasC = $_POST["respostas"][$c];
            $rc[] = $respostasC;
            $questoesC[] = $valor->attributes()->numero;
         }else{
            $somarE[0] = $cc++;
            $respostasE = $_POST["respostas"][$c];
            $rr[] = $respostasE;
            $questoesE[] = $valor->attributes()->numero;
        }
}
$respostasCorretas = implode(', ', $rc);
$questoesCorretas = implode(', ', $questoesC);
$respostasErradas = implode(', ', $re);
$questoesErradas = implode(', ', $questoesE);
    
06.06.2016 / 00:34