PHP: is_integer() function
Description
The is_integer() function is used to test whether the type of the specified variable is an integer or not. This function is an alias of is_int().
Version:
(PHP 4 and above)
Syntax:
is_integer(var_name)
Parameter:
Name | Description | Required / Optional |
Type |
---|---|---|---|
var_name | The variable being checked | Required | Mixed* |
*Mixed : Mixed indicates that a parameter may accept multiple (but not necessarily all) types.
Return value:
TRUE if var_name is an integer, FALSE otherwise.
Value Type: Boolean
Example:
<?php
$var_name1=678;
$var_name2="a678";
$var_name3="678";
$var_name4=999;
$var_name5=698.99;
$var_name6=array("a1","a2");
$var_name7=+125689.66;
if (is_integer($var_name1))
{
echo "$var_name1 is Integer<br>" ;
}
else
{
echo "$var_name1 is not an Integer<br>" ;
}
if (is_integer($var_name2))
{
echo "$var_name2 is Integer<br>" ;
}
else
{
echo "$var_name2 is not Integer<br>" ;
}
$result=is_integer($var_name3);
echo "[ $var_name3 is Integer? ]" .var_dump($result)."<br>";
$result=is_integer($var_name4);
echo "[ $var_name4 is Integer? ]" .var_dump($result)."<br>";
$result=is_integer($var_name5);
echo "[ $var_name5 is Integer? ]" .var_dump($result)."<br>";
$result=is_integer($var_name6);
echo "[ $var_name6 is Integer? ]" .var_dump($result)."<br>";
$result=is_integer($var_name7);
echo "[ $var_name7 is Integer? ]" .var_dump($result);
?>
Output:
678 is Integer a678 is not Integer bool(false) [ 678 is Integer? ] bool(true) [ 999 is Integer? ] bool(false) [ 698.99 is Integer? ] bool(false) [ Array is Integer? ] bool(false) [ 125689.66 is Integer? ]
View the example in the browser
Practice here online :
See alsoIt will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/php/function-reference/is_integer.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics