Odd or even numbers

Check if a number is odd or even in PHP

We know that any intege that is divisible by 2 is an even number else the number is an odd.

The code below will check if a number is odd or even:


$number = 5; //your input

if( $number % 2)
echo 'A number is even';
echo 'A number is an odd';

In mathematics, % symbol denotes percentage(percent). But in computing, we call it modulo(sometimes called modulus). The modulo operation finds the remainder after division of one number by another.


5 % 2 ; //the answer is 1
6 % 3 ; //returns 0
3 % 2 ; //returns 1

If you have additional information, please don’t forget to comment below.

Leave a Reply

Your email address will not be published. Required fields are marked *