Re: odd and even numbers

From: Date: Fri, 16 Jan 2004 20:35:26 +0000
Subject: Re: odd and even numbers
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-174874@lists.php.net to get a copy of this message
On Fri, Jan 16, 2004 at 02:30:59PM -0600, Jeremy wrote: > function isOdd ($value) { > return (int)$value % 2 ? true : false; > } > > Returns true/false if the value is odd. Also rounds down floating point numbers given as the > test value. No need to explicitly state "true" and "false". Just negate the result of your modulus operator, and take advantage of the fact that "0" is false, and "1" is true: function isOdd ($value) { return !((int)$value % 2); } -- [ joel boonstra | gospelcom.net ]

« previous php.general (#174874) next »