PHP is_int() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Variables

Definition

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);
CallWhat 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

ParameterDescription
valueRequired. The variable or value to test.

Return Value

Return ValueDescription
booltrue 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.

PHP
<?php
var_dump(is_int(42));
var_dump(is_int("42"));
var_dump(is_int(4.0));
var_dump(is_int(-7));

How It Works

  1. 42 is a whole number, so it is an integer.
  2. "42" is in quotes, so it is a string and the result is false.
  3. 4. 0 has a decimal point, so it is a float, even though it equals 4.
  4. -7 is a negative whole number, so it is also an integer.

Example 2 — Large Numbers and Number Formats

Integers have a maximum size, and PHP supports several ways to write them.

PHP
<?php
var_dump(is_int(PHP_INT_MAX));
var_dump(is_int(PHP_INT_MAX + 1));
var_dump(is_int(0x1A));
var_dump(is_int(1_000));

How It Works

  1. PHP_INT_MAX is the largest integer PHP can store, so it is still an integer.
  2. Adding 1 goes past the limit, so PHP turns the result into a float and is_int() returns false.
  3. 0x1A is a hexadecimal number written in code. It is the integer 26.
  4. 1_000 uses an underscore to make a big number easier to read (PHP 7. 4+). It is still an integer.

Example 3 — Validating Text Input

Text from a form is a string, so is_int() fails. Convert it or validate it with filter_var().

PHP
<?php
$input = "25";

var_dump(is_int($input));
var_dump(is_int((int) $input));
var_dump(filter_var($input, FILTER_VALIDATE_INT));
var_dump(filter_var("25.5", FILTER_VALIDATE_INT));

How It Works

  1. $input holds the string "25", so is_int($input) is false.
  2. Casting with (int) turns it into a real integer, so the second check is true.
  3. filter_var() with FILTER_VALIDATE_INT checks the text and returns the integer 25.
  4. "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.

Next: is_integer()

is_integer() is an alias of is_int(). It checks whether a variable is an integer and retur.

is_integer() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful