What would you do if you had to show like, 50 random numbers. Write 50 lines of code? No! You can use loop functions.Loop functions are the most pratic wau for making actions in great scale (in this case, generating random numbers).
Let's see the random numbers script.
|
<?php // The number of actions (the number of random numbers) $total = 50;
// The "trick" for($i = 1; $i <= $total; $i++) { echo "Random number ".$i.": ".rand(1, 99999)."<br>"; } ?> |
This must generate 50 random numbers, in just 3 lines!
Obs.: see more about random numbers at http://www.devpapers.com/article/37
Very simple no? You can also use this dinamically, in a great number of cases.
Useful links:
www.php.net/for
www.php.net/while
www.php.net/rand