How to increment a number by 2 in a PHP For Loop
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. Here is an example of a for loop that starts at 0, ends at 10, and increments by 2 on each iteration:
This will output:
0 2 4 6 8 10
Watch a video course
Learn object oriented PHP
Another way you can increment the number by 2 is using the $i = $i + 2
instead of $i += 2
This will also output:
0 2 4 6 8 10