What is Loop

Loops in PHP are used to execute the same block of code a specified number of times. PHP supports following four loop types.

In PHP, we have the following loop types:

  • for - loops through a block of code a specified number of times.

  • while - loops through a block of code as long as the specified condition is true.

  • do...while - loops through a block of code once, and then repeats the loop as long as the specified condition is true.

  • foreach - loops through a block of code for each element in an array.