PHP For Loop Logic help

need help with php looping
this is what i have

<h1>Lottery Game</h1>
$x = rand(1,3);
echo"Today's lucky number is <font size=5 color=red>$x</font> <br>";
$y = rand(1,3);
echo"Your number is <font size=5 color=green>$y</font> <br>";
echo"<h1><font color=green>Congratulations, you win!</h1><h2><font color=green>Congratulations, you win!</h2><h3><font color=green>Congratulations, you win!</h3></font>";
echo"<h1><font color=red>Sorry, you lost :( Try again!</h1><h2><font color=red>Sorry, you lost :( Try again!</h2><h3><font color=red>Sorry, you lost :( Try again!</h3></font>";

so i want it to loop for $y based on the random number if my random number is 2 i want to show the text congratulaions you win twice in 2 different headers if the random number is 3 show the text three times just as it does in the link

<img src="/community/uploads/default/original/3X/4/f/4fedbb2cae38fda59593e8f5586a5cf67fd1b0f4.png" width="690" height="183">

Hi muffiser welcome to the forum.

Can you please format the code in your post and better explain what problem you’re having.

Forum Posting Basics

If i understand correctly. So this will get you started study the code and change things and see how they interact. There is an improvement that can be made to make this code more optimal i did not do that as i left it for you to learn on your own. But your not gonna get anywhere asking for help on how to do everything if you do not try to do it wrong first. Coding is about failing you don’t know how to do it right the first time 90% of the time. Thats why planning and mock ups, and prototypes are a must and testing are a must. So don’t be afriad to fail to the point you want to rip out your hair and study and research till you possibly cant wrap your head around the problem then ask for some help.

$x = rand(1,3);
$y = rand(1,3);

echo "Today's Lucky Number is: $x <br />";
echo "Your Number is $y <br />";

for($i = 0; $i < $y; $i++)
    if($x == $y){
		echo "Congratulations, you win! <br />";
         echo "Sorry, you lost :( Try again!<br />";

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.