1
Colleagues. I do not know if I was clear in my title, but I will try to explain 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 $value variable brings us. I tried to use Count($value), but it is bringing "111". How would I add up these values and return 3?
Hello Tiago. I did so, but it returns now 1 2 and not just 2
– user24136
I changed the code, put the
echo
outside theforeach
– Tiago S
It now returns no value
– user24136
Change the place of echo $value, put between the last two keys
– Diego
Hello diego, but put where exactly? inside the loop?
– user24136
It has to be out of the loop
– Tiago S
Hi Tiago. I did as mentioned, but unfortunately does not return values. It is null.
– user24136
You have to start the variable with zero
$valor = 0
before increasing.– user28595
I started and also nothing...
– user24136
@Jose Marcos start off outside the
for
, see an example: https://ideone.com/7rKta6– user28595
Maybe he’s not getting into the loop
– Tiago S
@Jose Marcos to start
$valor = 0
outside thefor
, remove the internal Else from if. So, even if it doesn’t enter, the result will be zero.– user28595
Using the tool @Diegof recommended http://ideone.com/hcLO6I this example works.
– Tiago S
Tiagos is sure it works?
PHP Notice: Undefined variable: valor in /home/1IA14d/prog.php on line 4
– user28595
have, please look at stdout the result.
– Tiago S
See the error that returns.
– user28595