Page 1 of 1
odd or even number
Posted: Wed May 25, 2005 7:44 am
by shiznatix
is there a way to tell if a number is odd or even? i am creating a table from a db but i was the css to go with it with the diffrent color rows for each and all that. im sure this is a easy one but my google search turned up nothing
Posted: Wed May 25, 2005 7:57 am
by JayBird
use this little function
Code: Select all
function oddeven($x){
if($x & 1) return "odd";
else return "even";
}
or
Code: Select all
if ($number % 2) {
// Odd
} else {
// Even
}
or
Posted: Wed May 25, 2005 7:59 am
by shiznatix
many thanks but how does that work? whats the & symbol do?
Posted: Wed May 25, 2005 8:05 am
by JayBird
shiznatix wrote:many thanks but how does that work? whats the & symbol do?
It is a bitwise operator...read about it
