# PHP | check if a number is Even or Odd

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
```

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

We can solve this problem in two different ways as described below:

1. 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

 ` `

Output :

```Odd
```

Time Complexity: O(1)

2. 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

 ` `

Output :

```Odd
```

Time Complexity: O(n)

3. Using Bit Manipulation:
In this method we will find bit-wise AND of the number with 1. If the bit-wise AND is 1, then the number is odd, else even.

Below is the implementation of above idea.

## PHP

 ` `

Output :

```Odd
```

Time Complexity: O(1)

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

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

Article Tags :
Practice Tags :

1

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.