Count result of a variable

1

Colleagues. I do not know if it was clear in my title, but I'll try to explain it here. I have the following code:

    foreach($notasAlunos as $notaAluno){                                   
    $resXML = $xml->avaliacao->disciplina->questao->resposta;
    if($resXML == $notaAluno){
        $valor = 1; 
        echo count($valor);
    }else{
        $valor = 0;
    }
    //echo $valor;
  }

I need to add the amount of "1" that the variable $ value brings us. I tried to use the count ($ value), but it's bringing "111". How would I add these values and return 3?

    
asked by anonymous 20.04.2016 / 16:37

1 answer

1

Use This:

    foreach($notasAlunos as $notaAluno){                                   
       $resXML = $xml->avaliacao->disciplina->questao->resposta;
       if($resXML == $notaAluno){
           $valor++;           
       }else{
           $valor = 0;
        }

    }
    echo $valor;

In your code you are always setting the variable $valor to 1;

In my code I'm always incrementing + 1;

    
20.04.2016 / 16:40