...

View Full Version : detect an odd or even number function



mat41
04-15-2004, 07:15 AM
Is there a php function to detect an odd or an even number?

raf
04-15-2004, 08:17 AM
There is now (see below). Just use the modulus. Like


function is_even($a){
$even = True;
if ($a % 2 != '0'){
$even = False;
}
return $even;
}
// example
for ($i=0;$i<=1000;$i ++){
if (is_even($i){
echo $i . ' is an even number.<br />';
} else {
echo $i ' is an odd number.<br />';
}
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum