PHP Recursion

BEGIN PHP output

Is 0 an integer? Yes
Is 7 an integer? Yes
And 3.5? No
What about -5? Yes
And -9.2? No


END PHP output

<?
function checkInteger($Number)
{
  if($Number > 1)
  {
    /*
    /** integer -1 is still an integer
    */
    return(checkInteger($Number - 1));
  }
  elseif($Number < 0)
  {

    /*
    /** numbers are symetrical so check positive version
    */
    return(checkInteger((-1)*$Number - 1));
  }
  else
  {
    if(($Number > 0) AND ($Number < 1))
    {
      return("No");
      }
      else
      {
      /* zero and 1 are integers by definition
      return("Yes");
    }
  }
}

print("Is 0 an integer? " . checkInteger(0) . <br>"\n");
print("Is 7 an integer? " . checkInteger(7) . <br>"\n");
print("And 3.5? " . checkInteger(3.5) . <br>"\n");
print("What about -5? " . checkInteger(-5) . <br>"\n");
print("And -9.2? " . checkInteger(-9.2) . <br>"\n");
?>

Back to Bill's PHP