Thursday, 28 December 2017

PHP while, do, for, foreach - Looping structures

PHP for circles execute a piece of code a predefined number of times. The PHP for Loop. The for circle is utilized when you know ahead of time how frequently the content should run.

Looping structures

1. while ($n < 10) {
print("$n ");
$n++;
}

2. do {
print("$n ");
$n++;
}
while ($n < 10);

3. for ($n = 1; $n < 10; $n++)
print("$n ");

4. foreach ($myarray as $item)
print("$item ");

No comments:

Post a Comment