I have this code:
<?php
$counter = 1;
while ($counter == 5) {
echo "foo<br />";
$counter++;
}
?>
What I am expecting is to print foo 5 times on a separate lines. But what I get is a never ending loop. Are PHP while loops special? because when I do similar thing in Python, it works fine.
You want
while ($counter <= 5). That means “loop through this as long as$counteris less than or equal to5“.The way you have it written, it is saying “loop through this as long as
$counterequals5“. Since$counteris1the first time it gets to your loop, it skips the loop entirely!