Find given number is odd or even using php

Find given number is odd or even using php

Find given number is even or odd using php is very easy

The following operator used to find if a given number is even or odd.

First Method

The modulo operator % used to calculate the remainder of the value divided by 2. The remainder value of 0 for even, 1 for odd. The remainder value 0 equal to false 1 equal to true.


$value = 10;

If($value%2){

    echo “$value is odd”;

}else {

echo “$value is even”;

}

Second Method

The AND method & with the number 1. The AND operator perform a bitwise calculation on the number and 1. The returning value 0 is even, 1 is odd


$value = 10;

If($value&1){

echo “$value is odd”;

} else {

echo “$value is even”;

}

Third Method

The strops method is used to find give number is even or odd.

 


$a = 10;

$b = $a/2;

If(!strpos($b)){

echo “$value is odd”;

} else {

echo “$value is even”;
}

0 Comments

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed

>