How to print even numbers in PHP?

Member

by denis , in category: PHP General , 4 months ago

How to print even numbers in PHP?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by darion , 4 months ago

@denis you can use for loop and check with if statement even numbers or not in PHP, code:


1
2
3
4
5
6
7
8
<?php

for ($i = 0; $i <= 20; $i++) {
    if ($i % 2 === 0) {
        echo $i;
    }
}
// Output: 0 2 4 6 8 10 12 14 16 18 20