tags:

views:

507

answers:

3
<?php

$i = 0;

while(conditionals...) {

if($i == 0)
  print "<p>Show this once</p>";

print "<p>display everytime</p>";
$i++;
}
?>

Would this only show "Show this once" the first time and only that time, and show the "display everytime" as long as the while loop goes thru?

+5  A: 

Yes, indeed.

You can also combine the if and the increment, so you won't forget to increment:

if (!$i++) echo "Show once.";
pts
+2  A: 

Yes, as long as nothing in the loop sets $i back to 0

workmad3
+1  A: 

Yes it will, unless the conditions are false from the start or $i was set to 0 inside the loop

Nadia Alramli