For Loofs in PHP

In for-loop initialization, condition and increment happen on the same line. The loop keeps on repeating as long as the condition is true.

When the for loop is executed, the variable of the loop is initialized first and then the condition is checked. If the condition is true, then the program control goes to the statement block of the for loop and executes the statements there. When the For Loop statement executes all the statements in the block, it executes the step size part of the loop before exiting the block.
Then does the condition check back. If the condition is true then goes back to the statement block.

This sequence continues as long as the condition of the for loop remains true. Initialization of the loop happens only once.


for( initialization; condition;  increment ){


    echo "This is for loop in action <br>";

    for ($index=1; $index < 5; $index++) { 
        // for(initialization;condition; updation)
        echo "This number is $index <br>";

    echo "For loop has ended";


Related Posts

PHP explode() Function Example Tutorial

A PHP explode function example is given in this article. I will demonstrate how to use PHP’s explode string to array function. This is a basic example…

How to Convert Array to String in PHP?

We will cover the example of converting an array to a string in PHP in this lesson. We’ll examine an example of converting an array to a…

How Can I Convert a String in PHP Into an Array?

We will go over how to transform a string into an array in PHP in this little tutorial. Describe how to convert a string value into an…

How to Use the array_merge() Function in PHP?

We will go over the simple and quick method to use the PHP array_merge() function example in this brief tutorial. Let’s talk about the PHP example of…

How to Merge Two Arrays in PHP?

I explained simply how to merge two arrays in PHP Laravel. you will learn how to append two arrays in PHP. you will learn how to merge…

How to Get the First 5 Elements of Array in PHP?

Here, I will show you the php array to get the first 5 elements. let’s discuss about php array getting 5 first element values. you can see…

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x