RE: [PHP] Anyway of knowing whether a integer is odd or even

From: Date: Tue, 09 Oct 2001 17:07:17 +0000
Subject: RE: [PHP] Anyway of knowing whether a integer is odd or even
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-70516@lists.php.net to get a copy of this message
It is generally faster to use bitwise operators... if ($theInt & 1) print "$theInt is odd"; else print "$theInt is even"; This is usually the case for most languages, like C or C++ or what have you. It's probably the same in PHP, since the & operator doesn't need to worry about returning the remainder, just the bits that are set in both $theInt and 1. J Stewart Taylor wrote: > Sorry ignore my previous message I misread the question. > > If an integer is old then ($theInt % 2) > 0. > If event then ($theInt % 2) == 0 > > Here % = modulus operator which returns remainder of a division. > > -Stewart > > -----Original Message----- > From: Taylor, Stewart [mailto:Stewart.Taylor@uk.thalesgroup.com] > Sent: 09 October 2001 15:10 > To: 'Sam' > Cc: php-general@lists.php.net > Subject: RE: [PHP] Anyway of knowing whether a integer is odd or even > > > $color = "white"; > > while .. > { > display row using $color > > > $color = ($color=="white" ? "grey" : "white"); > } > > -Stewart > > -----Original Message----- > From: Sam [mailto:Sam@dragoman.co.uk] > Sent: 09 October 2001 14:31 > To: 'php' > Subject: [PHP] Anyway of knowing whether a integer is odd or even > > > Hi all, > > I have a query which returns X amount of rows. > I would like to display even rows one colour and odd rows a different > colour. > Is there a way to do this? > > Thanks in advance, > > Sam Rose > > p.s. Also I'm only on the digest, so if you could reply directly to me as > well, that would be a bonus. >

« previous php.general (#70516) next »