Hello, I would like to keep this thread open to ask questions whenever i get stuck while i'm learning PHP and would really appreciate any help given, since i'm starting out low, my first few questions would probbably be really stupid.
I started going through the W3schools PHP tutorials and got to the while loops section, Since it was pretty short i decided to make things a little bit more complicated for myself but in the end i didn't quiet manage to get it to work, would be nice if someone could point to the right direction of what i was doing wrong.
What i was trying to do was basicly generate a random number and depending on the value of the number, either increment or decrement another variable which is used in the loop to create a luck based loop which could go on forever if lucky (or unlucky). I know it's not a good idea to do create long loops especcialy ones that totally depend on luck but i just wanted to get it to work and see what happens.
This is the code i started with:
$i = "2";
srand(time());
$k = (rand()%3);
if ("$k =>2")
{
$i++;
}
else
{
$i--;
}
while ("1<=$i<=9")
{
echo "The number is ". $i . "
";
}
This didn't work so i tried to delete the if and try to work myself up so i did this:
while ("1<=$i<=9")
{
echo "The number is ". $i . "
";
$i++;
}
Which only worked with "" marks in but even after it "worked" it listed all the numbers it possibly can, crashing IE :(.
I tried changing the condition to
("$i=>1 && $i<=9")
But with the same crashing result as the above.
I'm trying something impossible or i'm just doing stupid mistakes?
Thanks