note 29030 added to ref.math

From: Date: Thu, 30 Jan 2003 20:15:05 +0000
Subject: note 29030 added to ref.math
Groups: php.notes 
Request: Send a blank email to php-notes+get-43152@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. -- http://www.php.net/manual/en/ref.math.php http://master.php.net/manage/user-notes.php?action=edit+29030 http://master.php.net/manage/user-notes.php?action=delete+29030 http://master.php.net/manage/user-notes.php?action=reject+29030

« previous php.notes (#43152) next »