In PHP, is_int() checks whether a variable is an integer, which is a whole number with no decimal part. It returns true for integers and false for every other type.
is_int() tests the type, not the look of the value. The integer 42 is true, but the string "42" and the float 42.0 are false. It is the preferred name for the aliases is_integer() and is_long().
Syntax
Call is_int() with the values you need. Start with this line.
PHP
$result = is_int($value);
Call
What it does
is_int(42)
Returns true, because 42 is an integer.
is_int("42")
Returns false, because a number in quotes is a string.
is_int(4.0)
Returns false, because 4.0 is a float.
Data from forms, URLs and files is always a string. To check that such text holds a whole number, use filter_var($text, FILTER_VALIDATE_INT) or ctype_digit(), not is_int().
Library declarations
PHP
is_int(mixed $value): bool
Parameters
Parameter
Description
value
Required. The variable or value to test.
Return Value
Return Value
Description
bool
true if the value is an integer, otherwise false.
PHP Examples
Example 1 — Integers and Non-Integers
Test a whole number, a numeric string, a float with no decimals and a negative number.
$input holds the string "25", so is_int($input) is false.
Casting with (int) turns it into a real integer, so the second check is true.
filter_var() with FILTER_VALIDATE_INT checks the text and returns the integer 25.
"25. 5" is not a whole number, so filter_var() returns false. This is the safe way to validate input.
Frequently Asked Questions
is_int() returns true if a variable is an integer (a whole number) and false for any other type, including floats and numeric strings.
Because "42" is a string. is_int() checks the type, not whether the text looks like a number. Use is_numeric() or filter_var() to check strings.
They are the same function. is_integer() and is_long() are aliases of is_int(), which is the preferred name in modern PHP.
No. 5.0 is a float. If you need to check that a float holds a whole number, use floor($x) == $x or compare it with intval($x).
Use filter_var($input, FILTER_VALIDATE_INT). It returns the integer when the text is valid and false when it is not. Remember that 0 is a valid result, so compare with === false.