FOR LOOP in PHP

<!DOCTYPE html>
<html lang=”en-US”>
<head>
<meta charset=”UTF-8″>
<title>LOOP </title>

</head>
<body>
<?php
$person=array(“VATSAL”,”KARAN”,”MILAN”);
foreach($person as $name)
{
print “<p>HAPPAY DIWALI $name</p>”;
}

?>
</body>
</html>

In this program array($person=array()) is an inbuilt function which declare/initialize array.we can also declare/initialize array as follow:

$person[0]=”VATSAL”;

$person[1]=”KARAN”;

$person[2]=”MILAN”;

In for-each loop $person element fetch one by one in $name and print message.

Leave a comment