[PHP] storing the value of rand() in a variable.?

yahoo

New member
I need to store the value of the generated random number inside a variable. e.g.

<?php
$randomnumber = rand('1000','9999'); //This will give me a four-digit random number.

echo "Number 1: ".$randomnumber;
echo "Number 1: ".$randomnumber;

?>

But the problem occurs when i run this:

Number 1: 1874
Number 2: 3624

It re-generates another random number when i try to use the variable again. How do i generate a number then store the random number in a variable so i can use the same variable(with the same number) again and again?
 
I typed in your program exactly as is and it worked fine for me. (I got the same number twice)

I noticed that your sample output has a Number 2 but your sample code says Number 1 so are you really giving us the output from that code?!
 
Back
Top