Contents
hide
Print Even Numbers in PHP
<?php
$i = 1; // Statement initialises i to 1
echo “This will print even numbers between 1 to 11”; // Prints the statement in double quotes
while($i <= 11) { // Check whether condition is true
if ( $i % 2==0) // Checks divisibility by two
echo “$i</br>”; // Prints Even numbers
$i++; // Increases value of i by 1
}
?>
___________________________
Output-
2
4
6
8
10
___________________________
$i = 1; // Statement initialises i to 1
echo “This will print even numbers between 1 to 11”; // Prints the statement in double quotes
while($i <= 11) { // Check whether condition is true
if ( $i % 2==0) // Checks divisibility by two
echo “$i</br>”; // Prints Even numbers
$i++; // Increases value of i by 1
}
?>
___________________________
Output-
2
4
6
8
10
___________________________