Hello.
The problem with your code is that it only does one iteration.
<?php
$var=rand(1,5); // get a number
while ($var==5) { // while the number is 5, print the number
echo $var;
}
?>
So, if $var gets the number 5 (1 in 5 chance) then your script will continue to print 5 forever (since you do not change the value in the loop).
I think you are looking for
do {
$num = rand(1,5);
echo $num;
if($num == 5)
exit;
} while($num != 5);
Alternatively (there are a million ways to do this)
<?php
$num = 0;
while($num != 5){
$num = rand(1,5);
echo $num;
}