mardi 24 janvier 2017

How do I add together Random Integers from a for loop with PHP

I was messing around with PHP and I figured out how to list 5 random integers between 1 and 100 using a for loop:

for($row = 1; $row <= 5; $row++) { 
    echo rand(1,100) . "<br>";
}

Now what I want to do is to add code that will let those rands be added up to a sum. And I can't figure out how to do it.

$value = 
$sum = $value;
echo $sum;

I know that those are the variable I need but I don't really know how to use them.
I want to take the 5 rand values that are echoed in each row and add them to create a sum value which will also be echoed. But how??
I am so lost and the best I can do is try to explain what I want without figuring out how to do it.




Aucun commentaire:

Enregistrer un commentaire