A number is called even if the number is divisible by 2 and is called odd if it is not divisible by 2. Given a number, we need to check whether it is odd or even in PHP.
Examples :
Input : 42 Output : Even Explanation: The number 42 is divisible by 2 Input : 39 Output : Odd Explanation: The number 39 is not divisible by 2
We can solve this problem in two different ways as described below:

Using modulo (%) operator: This is the simplest method of checking for even and odd and in this method, we simply check whether the number is divisible by 2 or not using the modulo ‘%’ operator.
Below program explains the above approach:
PHP
<?php
// PHP code to check whether the number
// is Even or Odd in Normal way
function
check(
$number
){
if
(
$number
% 2 == 0){
echo
"Even"
;
}
else
{
echo
"Odd"
;
}
}
// Driver Code
$number
= 39;
check(
$number
)
?>
chevron_rightfilter_none
Output :Odd
Time Complexity: O(1)

Recursive method: In the recursive approach, we reduce the number by 2 in each recursive call. If the final number is 0 then its even or else it is 1, the result will be odd.
Below is the implementation of above approach:
PHP
<?php
// Recursive function to check whether
// the number is Even or Odd
function
check(
$number
){
if
(
$number
== 0)
return
1;
else
if
(
$number
== 1)
return
0;
else
if
(
$number
<0)
return
check(
$number
);
else
return
check(
$number
2);
}
// Driver Code
$number
= 39;
if
(check(
$number
))
echo
"Even"
;
else
echo
"Odd"
;
?>
chevron_rightfilter_none
Output :Odd
Time Complexity: O(n)

Using Bit Manipulation:
In this method we will find bitwise AND of the number with 1. If the bitwise AND is 1, then the number is odd, else even.Below is the implementation of above idea.
PHP
<?php
// PHP code to check whether the number
// is Even or Odd using Bitwise Operator
function
check(
$number
)
{
// One
$one
= 1;
// Bitwise AND
$bitwiseAnd
=
$number
&
$one
;
if
(
$bitwiseAnd
== 1)
{
echo
"Odd"
;
}
else
{
echo
"Even"
;
}
}
// Driver Code
$number
= 39;
check(
$number
)
?>
chevron_rightfilter_none
Output :Odd
Time Complexity: O(1)
Recommended Posts:
 PHP  Separate odd and even elements from array without using loop
 Even digits Sum and Odd digits sum divisible by 4 and 3 respectively
 Largest Even and Odd Ndigit numbers
 Replace the odd positioned elements with their cubes and even positioned elements with their squares
 Increment odd positioned elements by 1 and decrement even positioned elements by 1 in an Array
 Use of :even and :odd pseudoclasses with list items in CSS
 Program to calculate the number of odd days in given number of years
 PHP  Check if a number is Perfect number
 PHP  Check if a number is armstrong number
 Smallest odd number with N digits
 PHP  Check if a number is prime
 Smallest Even number with N digits
 Number of ways to select exactly K even numbers from given Array
 Check if a number has same number of set and unset bits
 jQuery  :odd Selector
 AngularJS  ngclassodd Directive
 jQuery odd() Method
 PHP  Palindrome Check
 PHP to check substring in a string
 PHP program to check for Anagram
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : ShivamKD