Types of Loops in PHP

Rumman Ansari   Software Engineer   2020-02-04   5570 Share
☰ Table of Contents

Table of Content:


In PHP, we have the following loop types:

  • 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
  • for - loops through a block of code a specified number of times
  • foreach - loops through a block of code for each element in an array

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