Explode without foreach

0

Colleagues.

I am bringing from the bank the grades of the students that are as follows:

  

A, C, A, A, A, B, C, B, D, A, C, D, B, B, B, A

But I need to compare with the template notes that come from XML and thanks to the help of my colleagues, I came up with the following code:

   $contar = 0;
    $notasAlunos = explode(',',$aluno->avaliacao_respostas);
    foreach($xml->avaliacao->disciplina as $disciplina) {
           echo $disciplina->attributes()->nome.":<br>";
           foreach ($disciplina as $questao) {
                    foreach($notasAlunos as $notaAluno){ // Aqui trago as notas dos alunos
                            if($questao->resposta == $notaAluno){ // aqui verifico se as questões do gabarito é igual a nota do aluno
                               $conta = $contar++;                       
                           }                
                    }   
           }
    }
echo $conta;

The only problem is that when I use it that way, instead of bringing me 17 points, it's bringing me 91.

    
asked by anonymous 21.04.2016 / 15:01

1 answer

2

Try this:

$contar = 0;
$notasAlunos = explode(',',$aluno->avaliacao_respostas);
foreach($xml->avaliacao->disciplina as $disciplina) {
    echo $disciplina->attributes()->nome.":<br>";
    foreach ($disciplina as $key => $questao) {
        if($questao->resposta == $notaAluno[$key]){
            $contar++;                       
        }                  
    }
    echo $contar;
    $contar = 0;
}

Thus, you display the course note as soon as the loop responsible for counting the assignments ends, and then zeroes the variable so that it does not add up correct values for other courses.

    
21.04.2016 / 15:36