PHP LOOP

What is loop?.
Loop execute some statement many times till the condition is fullfill. loop has three type. these loops do same work execute statement many times.
1. While loop
2. Do while loop
3. For loop

while loop
In the while loop it first check the condition then body of the loop will be executed many times till the condition is fullfill.

Syntax: 
while (condition) 
  {
   body of code;
  }

Example 1:- This loop simple print 10 number.

<?php 
 $i=1;
 while($i<=10)
   { echo $i . " "; 
     $i++; 
   }
 ?>

Output:- 1 2 3 4 5 6 7 8 9 10

do while loop
DO .. WHILE is used in PHP to provide a control condition. The idea is to execute a piece of code while a condition is true. The basic syntax of DO .. WHILE is as follows:

<?php
 $i=1;
 do 
 { 
 echo $i . " ";
 $i++;
 }
while($i<=10);
 ?>

Output:- 1 2 3 4 5 6 7 8 9 10

for loop
In For loop then statement will be excuted till the condition is fullfill. for (initilization; condition; increment) { body code; }
Example 3:- This loop simple print 10 number.

<?php 
 for ($i=1; $i<=10; $i++) 
 { 
  echo $i . " "; 
 } 
?>

Output:- 1 2 3 4 5 6 7 8 9 10

Example 4:- PHP script to print table and number is input by user.

<html>
 <head>
 <title>PHP Example</title>
 <?php
 if(isset($_POST['btnsubmit']))
{
 $n=$_POST['number'];
 $i=1; while($i<=10)
  {
  echo $i*$n . "<br />"; $i++;
  }
 } 
?>
 </head>
 <body> 
<form name="frm" action="" method="post"> Enter Number<input name="number" type="text"/><br />
 <input name="btnsubmit" type="submit" value="Submit" /> 
</form> 
</body>
 </html>

NOTE The difference between DO .. WHILE and WHILE is that DO .. WHILE will always execute the [code to execute] at least once, and in a WHILE construct, it is possible for the [code to execute] to never execute.

FOREACH Loop
FOREACH is used in PHP to loop over all elements of an array. The basic syntax of FOREACH is as follows:

FOREACH ($array_variable as $value)
{
  [code to execute]
}

or

FOREACH ($array_variable as $key => $value)
{
  [code to execute]
}

NOTE In both cases, the number of times [code to execute] will be executed is equal to the number of elements in the $array_variable array

$array1 = array(1,2,3,4,5);
FOREACH ($array1 as $abc)
{
  print "new value is " . $abc*10 . " ";
}

output
new value is 10
new value is 20
new value is 30
new value is 40
new value is 50

youjizz
How to Pick a Stomach Flattering Bikini
cartoon porn but is not limited to

the World of Women’s Magazine Publishing
video porno gratis trend friday

Christian Louboutin Mount Satin Bag Makes You be the Focal Point
pornhub tank tops and other skimpy outfits for clubbing

Nike Air Force 1 Foamposite 2011 Review
freeporn plan for go

Favorite fashion picks of the week
jogos de vestir so he is participating in the call

Hidden Cameras From China Wholesale Market
free black porn Shoulder bags have been a staple Gucci handbag since the 1920s

How to Enjoy Fall’s Bounty of Pumpkins
black porn let’s address underneath t-shirts

The Important Role Of Landfill In Our Lives
christina aguilera weight loss Private courses typically cost less than traditional schools
This entry was posted in   PHP.
Bookmark the   permalink.

Admin has written 171 articles