PHP for loop is very similar to a while loop in that it continues to process a block of code until a statement becomes false, and everything is defined in a single line.



Syntax:

<?php 
for (variable; condition; increment/decrement){ 
  //code to be executed; 
} 
?> 

php-for

Example:

<?php 
for ($i=1; $i <= 5; $i++ ){ 
  echo "PHP for loop print $i times"."<br>";
} 
?>

Program Output:

PHP for loop print 1 times

PHP for loop print 2 times

PHP for loop print 3 times

PHP for loop print4 times

PHP for loop print5 times


Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram