note 29030 deleted from ref.math by victor
| From: | victor@php.net | Date: | Sat, 22 Feb 2003 15:45:38 +0000 |
| Subject: | note 29030 deleted from ref.math by victor | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-44348@lists.php.net to get a copy of this message | ||
There's no function to test whether an integer is even or odd. In PHP >4 you can do it
fairly easily by testing for the modulus of the number divided by 2, like this:
if ( fmod($num, 2) ) {
echo "$num is odd";
}
However, earlier versions lack the fmod() function, so you might have to do something like this:
$half = $num/2;
if ( $half - floor($half) ) {
echo "$num is odd";
}
Until there are built-in is_even() and is_odd() functions, the above should do the trick.