PHP Loop - php case - Phptpoint.com

What is Loop

/ins>

use of loop in PHP

When you want the same block of code to run over and over again in a row. Instead of adding several almost equal lines in a script we can use loops to perform a task.

OR

When you want to execute same statements more than one times then use loop.

Four types of Loop used in PHP :

  1. for : In for loop specified condition is predefined.
  2. while : while loop executes the statement while a specified condition is true.

    In while loop first check the condition then execute the statement.

  3. do-while : do – while loop executes the statement once and next statement depends upon a specified condition is true.

    In do – while loop first execute the statement then check the condition, it means if condition is false in that case one time statement execute.

  4. foreach : Foreach loop executes the statement() of an associative array.