Re: odd and even numbers SOLVED

From: Date: Fri, 16 Jan 2004 20:57:05 +0000
Subject: Re: odd and even numbers SOLVED
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-174876@lists.php.net to get a copy of this message
----- Original Message ----- From: "joel boonstra" <jboonstra@gospelcom.net> To: <php-general@lists.php.net> Sent: Friday, January 16, 2004 3:35 PM Subject: Re: [PHP] odd and even numbers > 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 ] > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > Thanks everyone for the fast replys! Jake

« previous php.general (#174876) next »