Check if a number is odd or even in PHP
by Sam
We know that any intege that is divisible by 2 is an even number else the number is an odd.
The code below will check if a number is odd or even:
<?php
$number = 5; //your input
if( $number % 2)
echo 'A number is even';
else
echo 'A number is an odd';
?>
In mathematics, % symbol denotes percentage(percent). But in computing, we call it modulo(sometimes called modulus). The modulo operation finds the remainder after division of one number by another.
Example:
6 % 3 ; //returns 0
3 % 2 ; //returns 1
If you have additional information, please don’t forget to comment below.