Is a number even or odd? With PHP

By   /  March 24, 2013  /  No Comments


$num = 18;
if($num&1) {
echo 'The number is odd';
} else {
echo 'The number is even';
}

And a function:

function is_odd($n){
return (boolean) ($n % 2);
}

Leave a Reply

Your email address will not be published. Required fields are marked *