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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s