PHP Loop: For, ForEach, While, Do While [Example – for loop in php]

Today, We want to share with you for loop in php.In this post we will show you php for loop array length, hear for PHP Loop: For, ForEach, While, Do While [Example] we will give you demo and example for implement.In this post, we will learn about PHP Nested While Loops And Multiple Conditions with an example.

PHP While, Do-While, For and Foreach Loops

PHP for Loop

There are the following the Different Types of Loops in PHP

  • while
  • do…while
  • for
  • foreach

Example 1:





";
}
?>  




Results:

The Counter is: 0
The Counter is: 1
The Counter is: 2
The Counter is: 3
The Counter is: 4
The Counter is: 5
The Counter is: 6
The Counter is: 7
The Counter is: 8
The Counter is: 9
The Counter is: 10

Example 2:





";
}
?>  




Results:

The counter is: 0
The counter is: 10
The counter is: 20
The counter is: 30
The counter is: 40
The counter is: 50
The counter is: 60
The counter is: 70
The counter is: 80
The counter is: 90
The counter is: 100

PHP while Loop

";
}
?>

PHP do…while Loop

";
}
while($counter <= 3);
?>

PHP foreach Loop

";
}
?>
 "pakainfo Welcome",
    "email" => "[email protected]",
    "age" => 25
);
 
// Loop through websiteInfo array
foreach($websiteInfo as $key => $value){
    echo $key . " : " . $value . "
"; } ?>

I hope you get an idea about for loop in php.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment