Checking if a Number is Even or Odd in PHP


Determine if a number is even or odd by using the modulo operator %.

Source Code

$number = 4;
if ($number % 2 == 0) {
    echo "The number is even.";
} else {
    echo "The number is odd.";
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments