How to check even or odd number?


What is an Even Number?

An even number is a number which is divisible by 2 and the remainder of these numbers is always 0. For example : 0,2,4,6,8,10...etc.

What is an Odd Number?

An odd number is a number which is not divisible by 2 and the remainder of these numbers is always 1. For Example : 1,3,5,7,9,...etc.

How to check if a number is even or odd?

In this tutorial we will see how to check if a number is even or odd. This is a basic type of program.

$number = 14; // assign a number to a variable. like 15, 25,100
$sum = 0; // assign a variable in which you want to store sum digits.

//we have need to find remainder of that number.
$remainder = $number % 2;

//If the remainder is 0, then it means number is even.
if($remainder == 0){
    echo $number . ' is even!';
}else{
    echo $number . ' is odd!';
}

//output is:
//14 is even!.