close[x]


PHP

PHP-Home PHP-Environment Setup PHP-Syntax PHP-Run PHP in XAMPP PHP-Variable PHP-Comment PHP-Datatype PHP-String PHP-Operators PHP-Decision PHP-loop PHP-Get/Post PHP-Do While loop PHP-While loop PHP-For loop PHP-Foreach loop PHP-Array PHP-Multidimensional Arrays PHP-Associative Arrays PHP-Indexed Arrays PHP-Function PHP-Cookies. PHP-Session PHP-File upload PHP-Email PHP-Data & Time PHP-Include & Require PHP-Error PHP-File I/O PHP-Read File PHP-Write File PHP-Append & Delete File PHP-Filter PHP-Form Validation PHP-MySQl PHP-XML PHP-AJAX



learncodehere.com




PHP - Loop

PHP Loop is used to execute a statement or a block of statements, multiple times until and unless a specific condition is met.

This helps the user to save both time and effort of writing the same code multiple times..

Loops are used to execute the same block of code again and again, as long as a certain condition is true.

In PHP, we have the following loop types:

  • while : loops through a block of code if and as long as a 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. It works only on array and object.

  • loop

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