How much is 0 multiplied by any value? It’s 0, right? So it’s explained. Pure mathematics.
How much is 0 divided by any amount? Also 0.
Programming follows the mathematical rules.
If you put 1 in $r
Something may come out in multiplication, but it’s probably not what you want. In the division would probably be better another value, but it doesn’t seem that changing the operator makes sense in this code. Even it can probably be simplified, so it was presented.
If I had a bigger context I could improve more, but it’s better this way:
$r = 0;
for ($ranking = 1; $ranking <=5; $ranking++) {
$p = isset($_GET["n$ranking"])?$_GET["n$ranking"]:0;
echo "$ranking ° Numero: $p";
$r += $p;
}
There were unnecessary variables there.
If you want to multiply:
$r = 1;
for ($ranking = 1; $ranking <=5; $ranking++) {
$p = isset($_GET["n$ranking"])?$_GET["n$ranking"]:0;
echo "$ranking ° Numero: $p";
$r *= $p;
}
I put in the Github for future reference.
I didn’t even mention that this code has serious security issues because it picks up a piece of data that comes from the outside and trusts that it will be just right. But that’s another matter.
PS: is missing a ; (semicolon) in the last line of the code also.
– Leonardo
Yes, I must have done it in copy+Paste, thank you ^^
– Nicolas Guilherme