How To Check Number Is Odd Or Even

How To Check Number Is Odd Or Even in php. first we understand what is even and odd.

Even Number : A number is called even if the number is divisible by 2
Odd Number : A number is called odd if it is not divisible by 2.

Below are simple Examples for understand :
Input : 90
Output : Even
Explanation: The number 90 is divisible by 2

Input : 57
Output : Odd
Explanation: The number 57 is not divisible by 2

We have 2 method here to check given no is odd or even

Method 1:
$number = 5;
if($number % 2){
echo ‘Odd number!’;
}else{
echo ‘Even number!’;
}

Method 2:
function evenCheck($number){
return ($number%2 == 0);
}

How to use evenCheck function
$number = 20;
if(evenCheck($number)){
echo “Number is even”;
} else {
echo “Number is odd”;
}

 

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face – we are here to solve your problems.

I, Dayanand Saini,the founder and chief editor of www.webtechsource.com,have been working as a software engineer from last 4+ years. It's my hobby to learn new things and implement on live environment.

Leave a Reply

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

88 − = 83

%d bloggers like this: