Introduction
This article explains the "is_int()" function in PHP. The is_int() function determines whether the type of a specified variable is an integer.
Syntax
|
is_int($var_name); |
| Parameter | |
| Var name | The variable name of which the type is to be evaluated |
When the variable is an integer, true is returned otherwise false.
Example1
Checking a variable to determine if it is an integer or not using "if" and "else" statements. Such as:
<?php
if (is_int(23)) {
echo "is integer\n";
} else {
echo "is not an integer\n";
}
?>
Output

Example2
<?php
$var1="234";
$var2=999;
$var3=698.88;
$var4=array("a1","a2");
$var5=+123456.99;
$result=is_int($var1);
echo "[ $var1 is Integer? ]" .var_dump($result)."<br>";
$result=is_int($var2);
echo "[ $var2 is Integer? ]" .var_dump($result)."<br>";
$result=is_int($var3);
echo "[ $var3 is Integer? ]" .var_dump($result)."<br>";
$result=is_int($var4);
echo "[ $var4 is Integer? ]" .var_dump($result)."<br>";
$result=is_int($var5);
echo "[ $var5 is Integer? ]" .var_dump($result);
?>
Output

Sam HobbsPosted Feb 19, 2013, 12:45 PM
The PHP documentation needs an editor. The documentation of the is_int function says "Find whether the type of a variable is integer". That sure sounds innapropraite to me. Instead of "find" I think it should be "determine" or something else. The word "find" implies there is a lookup and/or a significant amount of processing and I doubt there is for this function. I assume the return value of this function is determined from data that is easily accessed by PHP.