For Loofs in PHP

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours scrolling social media and waste money on things we forget, but won’t spend 30 minutes a day earning certifications that can change our lives.
Master in DevOps, SRE, DevSecOps & MLOps by DevOps School!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

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.

Syntax:-

for( initialization; condition;  increment ){
	//statements;
}

Example:-

<?php
    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";
?>

Output:-

Related Posts

PHP – strip_tags() Replace with Spaces Example

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More

How to Get Duplicate Values from Array in PHP?

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More

PHP explode() Function Example Tutorial

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More

How to Convert Array to String in PHP?

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More

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

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More

How to Use the array_merge() Function in PHP?

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x