PHP program to find Odd or Even number Example

Are you a school / college student? then you are at the right place to learn something new.

Today you are going to learn how to find Odd or Even number in PHP.

To find the even number it is pretty basic, any number divisible by 2 is an even number

for eg:

10 ÷ 2 = 5, 5 is the quotient, reminder is 0

so, if the reminder is 0 (zero) then it is an even number other it is an odd number.

In PHP there are two operators (/) slash and (%) percentage, former one returns the quotient and the later one returns the reminder.

In our program we need to find the reminder to check whether the entered number is odd or even, the basic script would be this:

You got an Idea how the script will work right?

Here is the complete code for you:

And a demo:

5 thoughts on “PHP program to find Odd or Even number Example”

1. Himanshu tyagi says:

Thanks alot it is very simaple way for understand code.

2. divya says:

it’s very easy to understand …thanks

3. jhany says:

it is easy way to understandble to any one

4. Why do you need to have the 0+\$number for this to work? If I use it without the 0+, it breaks the code. I don’t understand the need for the 0+

5. James says:

How could you adjust the code to accept a number string such as 1, 4, 7, 9, 16, 18