# PHP Script to Check Number is Even or Odd using If-else | Ternary Operator

__PHP__ program to check whether a number is even or odd using an if-else statement.

In this article, you will learn how to make a PHP program to check whether a number is even or odd using an if-else statement.

### Example

**Input Number: 26**

**An input number is an even number.**

You should have the knowledge of the following topics in PHP programming to understand this program:

- PHP

statement**If-else** - PHP Ternary Operator

## What are even odd numbers?

There is if any integer number divided by 2 and its reminder equals zero then it is an even number and if the remainder is greater than zero then it is an odd number.

### Samples of even-odd Numbers

**Even Numbers: 0, 2, 4, 6, ...**

`Odd Numbers: 1, 3, 5, 7, ...`

### Source Code

```
<?php
// PHP Program to Check Whether a Number is Even or Odd using If-else Statement
$x = 26;
echo "Input Number: ", $x, "\n\n";
if ($x % 2 == 0) {
echo "The input number is even number.\n";
} else {
echo "The input number is odd number.\n";
}
?>
```

### Output

`Input Number: 26`

`The input number is even number.`

### Explanation

In this given program, we have taken input

from the user via the system console, Then we divided this input by **26**

and checked that it's a reminder.**2**

If its remainder is equal to zero then it's an even number otherwise odd number.

## PHP Program to Check Whether a Number is Even or Odd using Conditional Operator

```
<?php
// PHP Program to Check Whether a Number is Even or Odd using Conditional Operator
$x = 27;
echo "Input Number: ", $x, "\n\n";
$x = $x % 2 == 0 ? 1 : 0;
if ($x) {
echo "The input number is even number.\n";
} else {
echo "The input number is odd number.\n";
}
?>
```

### Output

`Input Number: 27`

`The input number is odd number.`