Initialization : is used to set a counter.
Condition : if condition is true loop will continue, if the condition is false loop ends.
Increment : used to increment the counter.
<!DOCTYPE html>
<html>
<head>
<title>PHP For Loops</title>
</head>
<body>
<?php
for ($ftl=1; $ftl<=5; $ftl++)
{
echo "The Number is : ".$ftl."<br />";
}
?>
</body>
</html>
PHP for each loop is used to traverse array elements.
For every loop iteration, the value of the current array element is assigned to $value
and the array pointer is moved by one, until it reaches the last array element.
The following example demonstrates a loop that will output the values of the given array ($Books):
<!DOCTYPE html>
<html>
<head>
<title>PHP For Each Loop</title>
</head>
<body>
<?php
$Books=array("HTML5","CSS3","JavaScript","jQuery","Bootstrap","PHP","MySQL");
foreach( $Books as $web_books )
{
echo "Books Name : $web_books<br />";
}
?>
</body>
</html>