PHP For Loop

PHP for loop can be used to traverse set of code for the specified number of times.

It should be used if number of iteration is known otherwise use while loop.

Syntax

Example

Output:

PHP Nested For Loop

We can use for loop inside for loop in PHP, it is known as nested for loop.

In case of inner or nested for loop, nested for loop is executed fully for one outer for loop. If outer for loop is to be executed for 3 times and inner for loop for 3 times, inner for loop will be executed 9 times (3 times for 1st outer loop, 3 times for 2nd outer loop and 3 times for 3rd outer loop).

Example

Output:

PHP For Each Loop

PHP for each loop is used to traverse array elements.

Syntax

Example

Output:

Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *