Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

Loops

PHP Loops

Often, when writing code, you want to run the same block repeatedly. Instead of adding multiple similar lines to a script, you can use loops. Loops allow you to execute the same block of code repeatedly as long as a specified condition is true.

In PHP, there are several types of loops:

  • while: Loops through a block of code as long as the specified condition is true.
  • do…while: Loops through a block of code once, 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.