Sum total value of a result with PHP

0

Colleagues.

I have the following code:

$c = 1;
foreach($xml->resultado as $listar => $valor) {
     if($_POST["respostas"][$c] == $respostas){
            $valor = "1";
            $somar = $c;
        }else{
            $valor = "0";
        }
$c++;
}
echo "Valor Total: " .count($c);

The $ value returns 1 for each successful question, so it looks like this:

Resposta A -> 1
Resposta B -> 1
Resposta C -> 1

I would like to add a total of 3, but it is always returning 1.

    
asked by anonymous 15.05.2016 / 21:25

1 answer

0

I have. For this I used:

$c = 1;
foreach($xml->resultado as $listar => $valor) {
     if($_POST["respostas"][$c] == $respostas){
            $valor = "1";
            $somar[0] = $c++;
        }else{
            $valor = "0";
        }
}
echo "Valor Total: " .array_sum($somar);
    
15.05.2016 / 21:30