PHP for loop

The for loop used when number of iterations is known, means you know how many times you want to execute a block of code.

Syntax

for(initialization; condition; increment/decrement){  
//execute the statement; 
} 
initialization: Initialize the loop initial value.
condition: check the condition is true.
execute the statement;
increment/decrement: Increase/decrease the loop counter value

Example- 1

for ($i = 1; $i <= 10; $i++) {
    echo $i;
}
//output: 12345678910

PHP Nested For Loop

PHP nested for loop means , we can use wthin loop. first loop($i) is outer loop and another loop is inner loop($j)

for($i=1;$i<=2;$i++){    
	for($j=1;$j<=2;$j++){    
		echo "$i   $j
"; } } /* output: 1 1 1 2 2 1 2 2 */