note 24859 deleted from function.floor by nlopess

From: Date: Thu, 10 Nov 2005 18:30:28 +0000
Subject: note 24859 deleted from function.floor by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-98401@lists.php.net to get a copy of this message
Note Submitter: madsen at webcode dot dk ---- 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...

« previous php.notes (#98401) next »