PHP: is_int() function
Description
The is_int () function is used to test whether the type of the specified variable is an integer or not.
Version:
(PHP 4 and above)
Syntax:
is_int(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_int($var_name1))
{
echo "$var_name1 is Integer<br>" ;
}
else
{
echo "$var_name1 is not an Integer<br>" ;
}
if (is_int($var_name2))
{
echo "$var_name2 is Integer<br>" ;
}
else
{
echo "$var_name2 is not Integer<br>" ;
}
$result=is_int($var_name3);
echo "[ $var_name3 is Integer? ]" .var_dump($result)."<br>";
$result=is_int($var_name4);
echo "[ $var_name4 is Integer? ]" .var_dump($result)."<br>";
$result=is_int($var_name5);
echo "[ $var_name5 is Integer? ]" .var_dump($result)."<br>";
$result=is_int($var_name6);
echo "[ $var_name6 is Integer? ]" .var_dump($result)."<br>";
$result=is_int($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 also
Previous: is_float
Next: is_integer
It 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://w3resource.com/php/function-reference/is_int.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics