Re: odd and even numbers
| From: | Brad Pauly | Date: | Fri, 16 Jan 2004 20:27:45 +0000 |
| Subject: | Re: odd and even numbers | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-174872@lists.php.net to get a copy of this message | ||
On Fri, 2004-01-16 at 13:17, Jake McHenry wrote:
> I have a random number being generated from 1 to 501, is there an easy way for me to tell if
> the result is an odd or even number?
Yep. The modulus operator (%). Your number mod 2 will be 1 if it is odd
and 0 if it is even.
http://us4.php.net/manual/en/language.operators.arithmetic.php
if ($your_number % 2) {
echo 'odd';
} else {
echo 'even';
}
- Brad