The last component can be seen like a block of code, so you can do the following...

for($index=10;$index > 0;$index-=2) {
    echo $index;
}

The -= is equivalent to $index = $index - 2

Answer from Guy Park on Stack Overflow
🌐
DaniWeb
daniweb.com › programming › web-development › threads › 373272 › decrementing-a-for-loop-in-php
Decrementing a FOR loop in PHP | DaniWeb
July 21, 2011 - As @IIM hinted, keep the loop pieces in the correct slots: initialize; condition; decrement. Do not put an assignment in the condition. Check your bounds to avoid off-by-one errors and empty loops when $rownum3 < 15.
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
What is a for loop used for?
It repeats code a set number of times. You use it for counting, processing arrays, or building output.
🌐
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
🌐
Meera Academy
meeraacademy.com › home › php for loop
php for loop example
September 15, 2020 - PHP loop used to execute same block ... for loop will continue, if condition is false the for loop terminated. Increment/Decrements = used to increment or decrements start counter....
🌐
Codefinity
codefinity.com › courses › v2 › 0c05828c-d5a8-4d45-9122-1fd85bd6a81b › f02374d2-6089-4990-b8d3-5107e7a523de › f047917c-741c-4732-a1d1-7921e73f181f
Learn Increment and Decrement | Loops
123456789 <?php // Initialize the counter variable $counter = 0; // `for` loop with prefix increment for ($i = 0; $i < 5; ++$i) { echo $i .
🌐
HowtoForge
howtoforge.com › home › loops in php
Loops In PHP
Increment / Decrement: this portion will either increment or decrement the initial value to continue. Let’s write the first programme that will use FOR loop to print equal sign (=) ten times in each row for hundred lines · <?php for($i=1; $i<=100; $i++) { echo "==========" .
🌐
EDUCBA
educba.com › home › software development › software development tutorials › php tutorial › for loop in php
For Loop in PHP | Emulate the Top 8 Examples of For Loop in PHP
March 17, 2023 - In this program, the increment and decrement are mentioned inside the for a loop after printing the value of I variable to continue the iteration. <?php //example to demonstrate for loop for($i=1;$i<=10;) { // declaring variable i declaring ...
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
Find elsewhere
🌐
HScripts
hscripts.com › tutorials › php › controlstructures › for-structure.php
PHP For Loop, Conditional Structure, Increment, Decrement, Example - Hiox online Tutorial
for (initializtion;condition;increment) {Statements}//true The "initializtion" is the initial value, "condition" is the condition value,"increment" is the increment or decrement value, every time based on the true value of "condition" the loop is executed, and at the end of every iteration it checks the value of "increment" &lt?php for($c=0;$c=2;$c++) { echo "The value c is $c"; break; } ?> In the above example the value of $c is between 0 and 2, after every iteration of the loop the value of $c is increased by 1, then checked with the end values that is 2.
🌐
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 - A for loop repeats code while a condition stays true. You define a start point, a test, and an update step. You can decrement, skip steps, or break out of the statement early.
🌐
GeeksforGeeks
geeksforgeeks.org › php › php-for-loop
PHP for Loop - GeeksforGeeks
August 25, 2022 - Update Expression: After executing the loop body, this expression increments/decrements the loop variable by some value. For example: $num += 2; Example 1: The following code shows a simple example using for loop.
🌐
Scaler
scaler.com › home › topics › php-tutorial › php for loop
PHP For Loop - Scaler Topics
April 13, 2024 - The initialization part sets the starting value of the loop variable, the condition part specifies the condition that must be true for the loop to continue executing, and the increment/decrement part modifies the value of the loop variable after each iteration. In addition to the basic syntax, the for loop can be extended with additional features such as a break statement to exit the loop early or a continue statement to skip to the next iteration. In PHP, a loop is a programming construct that allows you to repeat a block of code multiple times.
🌐
PGDBF
splessons.com › lesson › php-for-loop
PHP for Loop - SPLessons
April 11, 2017 - 3)Increment or Decrement : Once the loop gets executed the flow of control jumps back to Increment or Decrement section. Here the value gets incremented (or) decremented and again the control goes to condition section.
🌐
Stack Overflow
stackoverflow.com › questions › 32214285 › php-loop-same-loop-incrementing-and-then-decrementing
Php loop- same loop incrementing and then decrementing - Stack Overflow
Still keeps the while portion of the loop the same as what you have. Just increment/decrement and saves output to another variable to be echo'd later. <?php $x = 1; $y = 1024; $outputX = ''; $outputY = ''; while($x <= 512){ $outputX .= "{$x}<br>"; $outputY .= "{$y}<br>"; $x *= 2; $y /=2; } echo $outputX; echo $outputY; //need to output the last value of $y because the loop misses the last iteration of the second while loop.
🌐
CodeBasics
code-basics.com › programming › php course › increment and decrement
CodeBasics | Increment and decrement | PHP
They are very common with loops. These unary operations increment and decrement by one the number written in a variable: <?php $i = 0; $i++; // 0 $i++; // 1 $i--; // 2 $i--; // 1Expand code · When using the prefix form, it's the other way around.
🌐
Eduonix Blog
blog.eduonix.com › home › 2014 › october › php for loop
PHP For Loop
October 8, 2014 - Increment/decrement: the counter is incremented or decremented as specified. Let us understand deeply how the code in for loop is repeated specified number of times with an example. Create a new folder named for_loop in the htdocs folder inside xampp folder. Then open a new notepad++ document and save it as index.php ...
🌐
The Knowledge Academy
theknowledgeacademy.com › blog › php-for-loop
PHP For Loop: Introduction, Syntax, and Examples
March 5, 2026 - If the condition evaluates to true, the loop continues; otherwise, it terminates. 3) Increment/decrement: After each iteration, the loop counter or variables are updated to ensure progress towards the termination condition.
🌐
Pi My Life Up
pimylifeup.com › home › how to use the php for loop
How to Use the PHP for Loop - Pi My Life Up
April 12, 2022 - $y -= 10 will decrement our counter variable $y by 10 on every iteration. On every iteration, we echo the value of $y along with the line break HTML element. <?php for($y = 100; $y >= 50; $y -= 10) { echo "The value of y is " .
🌐
XYplorer
xyplorer.com › xyfc › viewtopic.php
Decrementing in a while loop - XYplorer Beta Club
January 15, 2015 - The help under increment states, "Note that before v14.30.0100 the value was incremented/decremented before it was passed to the function!" But, isn't that what is happening here, at least for decrementing? Thanks, Ken ... Maybe increment $i by one before looping, then $i-- in header of the loop?
🌐
DEV Community
dev.to › emilossola › learning-php-for-i-loop-how-to-do-3o3b
Learning PHP For i Loop: How to do? - DEV Community
May 31, 2023 - The basic structure of the for loop is as follows: for (initialization; condition; increment/decrement) { // code to be executed }
🌐
Tutorialspoint
tutorialspoint.com › php › php_for_loop.htm
PHP - For Loop
To have a for loop that goes from ... iteration checks whether it is greater than 1. The last expression to be executed at the end of each iteration should decrement it by 1. <?php for ($i=10; $i>=1; $i--){ echo "Iteration No: ...