Loops in PHP

A Loop is an Iterative Control Structure that involves executing the same number of code a number of times until a certain condition is fulfilled

Types of Loops in PHP

  1. while 
  2. do-while loop
  3. for loop
  4. foreach loop

1 . While :-The while loop is an entry control loop like for loops i.e., it first check the condition at the start of the loop and if its true then it enters the loop and executes the block of statement which is under block, and goes on executing it as long as the condition will true.

PHP while statement - w3resource
example of while loop:-

2 . DO- WHILE LOOP :- The block of code executed once and then condition is checked. If the condition is true the statement is repeated as long as the specified condition is true and if the condition will be false in first itteration then also the statement will be executed first time .

PHP do while statement - w3resource
example of do while loop :-

3 . FOR LOOP :-  For loop is commonly used to execute a code block a specific number of times. The syntax makes use of three expressions:

PHP For Loop and Foreach Loop | Studytonight
example of for loop :-

4 . FOREACH LOOP :-We use foreach loop mainly for loop through the value of an array. It loops over the array, and each value for the current array element is assigned to value, and the array pointer is advanced by one to go the next element in the array. Though foreach loop iterates over an array of elements.

PHP Foreach Loop | foreach loop statement | PHP Nested For Loop
example of foreach loop :-
php tutorial - PHP Foreach Loop - php programming - learn php - php code -  php script - wikitechy