RE: [PHP] Is it odd or even???

From: Date: Mon, 05 Mar 2001 20:32:49 +0000
Subject: RE: [PHP] Is it odd or even???
Groups: php.general 
Request: Send a blank email to php-general+get-42665@lists.php.net to get a copy of this message
> 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"; > > > > } Ours are identical, just the other way around. This: if( $num % 2 ) { means if the result of that operation is anything other than 0 (zero), which is a truth in PHP. Chris

« previous php.general (#42665) next »