Return to Snippet

Revision: 45263
at March 16, 2013 01:58 by tasmanweb


Updated Code
function is_int($int){
		if(is_numeric($int) === TRUE){
				return ((int)$int == $int) ? true: false;
		}
		return FALSE;
}
/*
    // test code
		print("155 - ".int(155)."<br>");
    print("15.5 - ".int(15.5)."<br>");
    print("\"155\" - ".int("155")."<br>");
    print("\"15.5\" - ".int("15.5")."<br>");
    print("\"0155\" - ".int("0155")."<br>");
    print("\"I'm 155\" - ".int("I'm 155")."<br>");
    print("\"test\" -- ".int(true)."<br>");
    print("\"\" - ".int(""));
*/

Revision: 45262
at April 28, 2011 01:07 by tasmanweb


Initial Code
function int($int){
		if(is_numeric($int) === TRUE){
				return ((int)$int == $int) ? true: false;
		}
		return FALSE;
}
/*
    // test code
		print("155 - ".int(155)."<br>");
    print("15.5 - ".int(15.5)."<br>");
    print("\"155\" - ".int("155")."<br>");
    print("\"15.5\" - ".int("15.5")."<br>");
    print("\"0155\" - ".int("0155")."<br>");
    print("\"I'm 155\" - ".int("I'm 155")."<br>");
    print("\"test\" -- ".int(true)."<br>");
    print("\"\" - ".int(""));
*/

Initial URL

                                

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

Initial Title
is_int(): accurately test for integer

Initial Tags
php, function

Initial Language
PHP