odd or even number

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

odd or even number

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

many thanks but how does that work? whats the & symbol do?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

shiznatix wrote:many thanks but how does that work? whats the & symbol do?
It is a bitwise operator...read about it :D
Post Reply