Loops in PHP

Loops in PHP are used if we want to execute a block of code for a specified number of times. There are four types of loops in PHP –

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

for loop:

Output –

while loop:

Output –

do…while loop:

Output –

foreach loop: Applicable only to arrays.

Output –

Receive our updates to your inbox

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.