|
Question : How do I find out weather a number is odd or even?Answer :Use the MOD (%) operator, for example like this:
$i = 10;
if ($i % 2) {
echo "$i is odd";
} else {
echo "$i is even";
}
it's suggested that one use the MOD operator, but performance wise it's much
better to use the & operator, thus:
$i = 10;
if ( $i&1 )
{
echo "$i is odd";
}
else
{
echo "$i is even";
}
|