RE: [PHP] Is it odd or even???
| From: | John Guynn | Date: | Mon, 05 Mar 2001 20:36:34 +0000 |
| Subject: | RE: [PHP] Is it odd or even??? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-42667@lists.php.net to get a copy of this message | ||
Color me confused because I though true was any non zero value and false was
zero.
I know I am using the following code:
if (!($num % 4){ do something}
and it does something when $num is evenly divisible by 4 (ie. $num % 4 = 0).
If I were testing for odd vs even I'd do the following:
if (!($num % 2) {
Odd
} else {
Even
}
John Guynn
This email brought to you by RFCs 821 and 1225.
-----Original Message-----
From: Boget, Chris [mailto:Chris.Boget@wild.net]
Sent: Monday, March 05, 2001 2:33 PM
To: 'Kenneth R Zink II'; Php (E-mail)
Subject: RE: [PHP] Is it odd or even???
> That won't work. % returns the remainder from a division of
> the number divided by the mod number.
Yours:
> if($num %2 == 0){
> echo "even";
> }else{
> echo "odd";
> }
Mine:
> > if( $num % 2 ) {
> > echo "Odd";
> >
> > } else {
> > echo "Even";
> >
> > }