Show this once

"; print "

d...">

Display text once inside while loop in first loop

<?php

$i = 0;

while(conditionals...) {

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

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

Will it only show "Show it once" for the first time and only that time and show "display every time" while the while loop goes through?

+3
source share
4 answers

Yes indeed.

You can also combine the if and increment values, so you will not forget to increase:

if (!$i++) echo "Show once.";
+11
source

, , , , 0 , . . , -. - :

<?php

   $i = 0;

   while(conditionals...) {

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

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

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

+2
source

Yes, this will happen if the conditions are not false from the very beginning or $ i was set to 0 inside the loop

+1
source

Source: https://habr.com/ru/post/1707808/


All Articles