🌐
W3Schools
w3schools.com › php › php_looping_for.asp
PHP for loop
The PHP for loop - Loops through a block of code a specified number of times.
🌐
PHP
php.net › manual › en › control-structures.for.php
PHP: for - Manual
In the beginning of each iteration, expr2 is evaluated. If it evaluates to true, the loop continues and the nested statement(s) are executed.
People also ask

How can I create HTML with a for loop?
You write HTML tags inside the loop body. PHP prints each piece as the loop runs.
🌐
flatcoding.com
flatcoding.com › home › php for loop: run code using a counter with examples
PHP For Loop: Run Code Using a Counter with Examples - FlatCoding
Can I skip steps in a for loop?
Yes. You use continue to jump to the next iteration without running the remaining code.
🌐
flatcoding.com
flatcoding.com › home › php for loop: run code using a counter with examples
PHP For Loop: Run Code Using a Counter with Examples - FlatCoding
🌐
w3htmlschool
w3htmlschool.com › home › phpfor
PHP for Loop Explained | Syntax, Examples & Best Practices
April 16, 2026 - 👉 In simple words: A PHP for loop runs code again and again until a condition becomes false. for (initialization; condition; increment/decrement) { // Code to execute } <?php // Step 1: Initialization for ($i = 1; $i <= 5; $i++) { // Step 2: Action inside the loop echo "Number: $i<br>"; } ?> $i = 1 → Loop starts from 1 ·
🌐
Plus2Net
plus2net.com › php_tutorial › php_for_loop.php
PHP for and foreach looping with break condtions & Step value of Increment
February 5, 2000 - for($i=1; $i<=10; $i++){ if($i == 5){continue;} // When value=5, below echo line is skiped. if($i == 7){break;} // When value=7, the loop is skiped. echo $i." "; } Output is 1,2,3,4 and 6. So far we have seen each time the variable value is increased by 1. This increase or step value can be changed.
🌐
freeCodeCamp
freecodecamp.org › news › how-loops-work-in-php-beginners-guide
How Loops Work in PHP: A Complete Guide for Beginners
June 18, 2025 - The step here is $i += 2, not just $i++. This adds 2 to $i after each run instead of 1. So the values go from 2 to 4 to 6. That is how you control the pace of the loop. ... In the following section, you will learn about another loop called foreach.
🌐
The Knowledge Academy
theknowledgeacademy.com › blog › php-for-loop
PHP For Loop: Introduction, Syntax, and Examples
March 5, 2026 - Let's understand how it works: 1) The initialisation step is executed first. Here, you initialise the For Loop counter or variables with their initial values. 2) Next, the condition is evaluated.
🌐
Scaler
scaler.com › home › topics › php-tutorial › php for loop
PHP For Loop - Scaler Topics
April 13, 2024 - In this example, we are using a for loop to print only the even numbers from 0 to 9. The loop starts at 1, continues until $i is less than or equal to 9, and increments $i by 2 after each iteration to skip odd numbers. A nested loop in PHP is a loop inside another loop.
🌐
Phpschools
phpschools.com › lesson › php-for-loop
php for loop - phpschools
December 13, 2025 - The increment or decrement part of a php for loop updates the counter after each iteration. This step ensures that the loop eventually reaches a point where the condition becomes false. ... This php for loop counts backward from 5 to 1. This example combines all components of a php for loop to display even numbers from 2 to 10.
Find elsewhere
🌐
FlatCoding
flatcoding.com › home › php for loop: run code using a counter with examples
PHP For Loop: Run Code Using a Counter with Examples - FlatCoding
July 1, 2025 - This loop counts from 1 to 3. It prints each number multiplied by 2 (2, 4, and 6). ... This loop counts backward from 3 to 1. It prints “Step” with each number (Step 3, Step 2, Step 1).
🌐
Tizag
tizag.com › phpT › forloop.php
PHP Tutorial - For Loop
Learn how to use a for loop in PHP with Tizag.com's PHP For Loop lesson.
🌐
C.S. Rhymes
csrhymes.com › 2021 › 09 › 13 › the-php-for-loop.html
The PHP for loop | C.S. Rhymes
September 13, 2021 - Instead, use descriptive variable names for you loop so you can better distinguish each variable in each loop. In this example we have 5 trees and each tree has 10 leaves. Don’t worry about the <br /> tag, that is just for formatting. for ($trees = 1; $trees <= 5; $trees++) { echo 'Tree ' . $trees . ' has leaves '; for ($leaves = 1; $leaves <= 10; $leaves ++) { echo $leaves . ', '; } echo '<br />'; } // Tree 1 has leaves 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // Tree 2 has leaves 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // Tree 3 has leaves 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // Tree 4 has leaves 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // Tree 5 has leaves 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
🌐
Scientech Easy
scientecheasy.com › home › blog › for loop in php
For Loop in PHP - Scientech Easy
February 2, 2026 - Let’s take an example of for loop in PHP that displays a multiplication table for a given number. ... <?php $num = 5; echo "Multiplication Table for $num: \n"; for($i = 1; $i <= 10; $i++) { $result = $num * $i; echo "$num * $i = $result\n"; } ?> Output: Multiplication Table for 5: 5 * 1 = 5 5 * 2 = 10 5 * 3 = 15 5 * 4 = 20 5 * 5 = 25 5 * 6 = 30 5 * 7 = 35 5 * 8 = 40 5 * 9 = 45 5 * 10 = 50
🌐
IONOS
ionos.com › digital guide › websites › web development › php: loops
How to use PHP loops to repeat program sequences automatically
April 10, 2024 - for (init counter; test counter; increment counter) { code to be iterated; }php · init counter: This initial value marks the starting point for the loop and is where you typically ini­tial­ize a variable. test counter: This condition is evaluated every time the loop runs. As long as this condition remains true, the loop body is executed. When the condition turns false, the loop stops executing. increment counter: This step specifies how the initial value is in­cre­ment­ed or decre­ment­ed with each pass of the loop.
🌐
W3Docs
w3docs.com › php
How to increment a number by 2 in a PHP For Loop | W3Docs
You can increment a number by 2 in a PHP for loop by using the increment operator (++) and adding 2 to it on each iteration.
🌐
GeeksforGeeks
geeksforgeeks.org › php › php-loops
PHP Loops - GeeksforGeeks
April 10, 2025 - In this article, we will discuss the different types of loops in PHP, their syntax, and examples. ... PHP for loop is used when you know exactly how many times you want to iterate through a block of code.
🌐
Codecademy
codecademy.com › learn › learn-php › modules › php-loops › cheatsheet
Learn PHP: Loops in PHP Cheatsheet | Codecademy
In PHP, while loops repeat execution of their code block as long as their conditional statement is true. ... In PHP, the foreach loop is used for iterating over an array.