Php Tutorial – CHAPTER 6: Loops in PHP


There are some basic statements that we can use in PHP to use loops.
These statements are.
- For
- While
- Do while
- For each
I would like show you some examples that you can apply on your
exercises in PHP. The following script corresponds to a loop where
the value will increase until the variable (j) is equal to 20.

<Html>
<head>
<title> WE ARE IN LOOP CHAPTER </title>
</head>
<body>
<span style="color: #ff0000;"><?php
$j=1;
while($j<=20)
{
echo "Our number is " . $i . "<br />";
$j++;
}
?></span>
</body>
</html>


On the other hand I would like to show another PHP script where the
text “I am the king of the word” will appear 7 times.

<Html>
<head>
<title> WE ARE IN LOOP CHAPTER </title>
</head>
<html>
<body>
<span style="color: #ff0000;"><?php
for ($k=1; $k<=7; $k++)
{
echo "I am the king of the world!<br />";
}
?></span>
</body>
</html>

You can leave a response, or trackback from your own site.

Leave a Reply

You must be logged in to post a comment.