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 - for Loop

The for statement is used when you know how many times you want to execute a statement or a block of statements.

The for loop - Loops through a block of code a specified number of times.

Syntax : for Loop


for (init counter; test counter; increment counter) {
  code to be executed for each iteration;
}

  • init counter : Initialize the loop counter value
  • test counter : Evaluated for each loop iteration. If it evaluates to TRUE, the loop continues.
  • increment counter : Increases the loop counter value
  • Let's put these syntax into real use.

    Example : for Loop

    
    <?php 
    for ($x = 10; $x <= 20; $x++) {
     echo "Number = $x <br>";
    } 
    ?> 

    This will produce the following result −

    Result

    Number = 10

    Number = 11

    Number = 12

    Number = 13

    Number = 14

    Number = 15

    Number = 16

    Number = 17

    Number = 18

    Number = 19

    Number = 20