I'm trying to generate 10 different number with rand() function using for loop. My codes:
<?php
$rand = rand();
for ($i=1 ; $i<=10 ; $i++){
echo $rand."\n";
}
?>
But when I run my code output something like that:
4481
4481
4481
4481
4481
4481
4481
4481
4481
4481
All 10 values are same, but I want to get all of them different.
In C, there is a srand(time(NULL)) code to prevent from this, what is the alternative solution in PHP?
Thanks.
Aucun commentaire:
Enregistrer un commentaire