English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP is_int()、is_integer()、is_long() function usage and example

PHP available functions

is_int() The function is used to check whether a variable is an integer.

Note: If you want to test whether a variable is a number or a numeric string (such as form input, which is usually a string), you must use is_numeric().

Alias function():is_integer()、is_long() .

PHP version requirement: PHP 4, PHP 5, PHP 7

Syntax

bool is_int ( mixed $var )

Parameter description:

  • $var:The variable to be checked.

Return value

If the specified variable is an integer TRUE, otherwise returns FALSE.

Online 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 an integer" . PHP_EOL ;
}
else
{
echo "$var_name1 Not an integer" . PHP_EOL ;
}
if (is_int($var_name2))
{
echo "$var_name2 Is an integer" . PHP_EOL ;
}
else
{
echo "$var_name2 Not an integer" . PHP_EOL ;
}
$result=is_int($var_name3);
echo "[ $var_name3 Is it an integer? ]" .var_dump($result) . PHP_EOL;
$result=is_int($var_name4);
echo "[ $var_name4 Is it an integer? ]" .var_dump($result) . PHP_EOL;
$result=is_int($var_name5);
echo "[ $var_name5 Is it an integer? ]" .var_dump($result) . PHP_EOL;
$result=is_int($var_name6);
echo "[ $var_name6 Is it an integer? ]" .var_dump($result) . PHP_EOL;
$result=is_int($var_name7);
echo "[ $var_name7 Is it an integer? ]" .var_dump($result);
?>

The output result is:

678 Is an integer
a678 Not an integer
bool(false)
[ 678 Is it an integer? ]
bool(true)
[ 999 Is it an integer? ]
bool(false)
[ 698.99 Is it an integer? ]
bool(false)
[ Array Is it an integer? ]
bool(false)
[ 125689.66 Is it an integer? ]

PHP available functions