PHP Loops

Loops рдПрдЙрдЯреИ рдХреЛрдб рдмреНрд▓рдХрд▓рд╛рдИ рдкрдЯрдХ-рдкрдЯрдХ execute рдЧрд░реНрди рдкреНрд░рдпреЛрдЧ рдЧрд░рд┐рдиреНрдЫ, рдЬрдмрд╕рдореНрдо рдПрдЙрдЯрд╛ рдирд┐рд╢реНрдЪрд┐рдд рд╕рд░реНрдд (condition) true рд░рд╣рдиреНрдЫред

PHP рдорд╛, рд╣рд╛рдореАрд╕рдБрдЧ рдирд┐рдореНрди loops рд╣рд░реВ рдЫрдиреН:

PHP `while` Loop

Example
<?php
$x = 1;
while($x <= 5) {
  echo "The number is: $x <br>";
  $x++;
}
?>

PHP `do...while` Loop

Example
<?php
$x = 1;
do {
  echo "The number is: $x <br>";
  $x++;
} while ($x <= 5);
?>

PHP `for` Loop

Example
<?php
for ($x = 0; $x <= 10; $x++) {
  echo "The number is: $x <br>";
}
?>

PHP `foreach` Loop

Example
<?php
$colors = array("red", "green", "blue", "yellow");

foreach ($colors as $value) {
  echo "$value <br>";
}
?>