Posted By

tasmanweb on 04/28/11


Tagged

php function


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

AllKnightAccess


is_int(): accurately test for integer


 / Published in: PHP
 

A better and more accurate function to see if a value is an integer.

  1. function is_int($int){
  2. if(is_numeric($int) === TRUE){
  3. return ((int)$int == $int) ? true: false;
  4. }
  5. return FALSE;
  6. }
  7. /*
  8.   // test code
  9. print("155 - ".int(155)."<br>");
  10.   print("15.5 - ".int(15.5)."<br>");
  11.   print("\"155\" - ".int("155")."<br>");
  12.   print("\"15.5\" - ".int("15.5")."<br>");
  13.   print("\"0155\" - ".int("0155")."<br>");
  14.   print("\"I'm 155\" - ".int("I'm 155")."<br>");
  15.   print("\"test\" -- ".int(true)."<br>");
  16.   print("\"\" - ".int(""));
  17. */

Report this snippet  

You need to login to post a comment.