PHP Loops

PHP supports several types of loops that allow you to execute a block of code repeatedly as long as a specified condition is true or for a fixed number of iterations. Here's an overview of the loops available in PHP:


  1. while loop: Repeats as long as a condition is true.
  2. do...while loop: Executes at least once, then continues as long as a condition is true.
  3. for loop: Used when the number of iterations is known.
  4. foreach loop: Used to iterate over elements in an array.


The following chapters will explain and give examples of each loop type.

Example
<?php
$i = 1;
while ($i <= 5) {
echo "Number: $i <br>";
$i++;
}
?>

Try it yourself


Whereisstuff is simple learing platform for beginer to advance level to improve there skills in technologies.we will provide all material free of cost.you can write a code in runkit workspace and we provide some extrac features also, you agree to have read and accepted our terms of use, cookie and privacy policy.
© Copyright 2024 www.whereisstuff.com. All rights reserved. Developed by whereisstuff Tech.