CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   detect an odd or even number function (http://www.codingforums.com/showthread.php?t=36907)

mat41 04-15-2004 08:15 AM

detect an odd or even number function
 
Is there a php function to detect an odd or an even number?

raf 04-15-2004 09:17 AM

There is now (see below). Just use the modulus. Like
PHP Code:

function is_even($a){
    
$even True;
    if (
$a != '0'){
        
$even False;
    }
    return 
$even;
}
// example
for ($i=0;$i<=1000;$i ++){
      if (
is_even($i){
           echo 
$i ' is an even number.<br />';
      } else {
           echo 
$i ' is an odd number.<br />';
      }




All times are GMT +1. The time now is 01:08 AM.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.