note 24859 added to function.floor

From: Date: Fri, 30 Aug 2002 12:43:58 +0000
Subject: note 24859 added to function.floor
Groups: php.notes 
Request: Send a blank email to php-notes+get-36035@lists.php.net to get a copy of this message
An easier way to check if a number is even or odd: if ($number % 2) { // Odd } else { // Even } If $number is even, ($number % 2) will return 0, which will be interpreted as false by the if-condition... Otherwise ($number % 2) will return a float, which will the be interpreted as true. Another way to do it could be to check if the return of ($number / 2) is an int. if (is_int($number / 2)) { // Even } else { // Odd } See: http://php.net/is_int Hope it helps someone... -- http://www.php.net/manual/en/function.floor.php http://master.php.net/manage/user-notes.php?action=edit+24859 http://master.php.net/manage/user-notes.php?action=delete+24859 http://master.php.net/manage/user-notes.php?action=reject+24859

« previous php.notes (#36035) next »