PHP is_long() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Variables

Definition

In PHP, is_long() checks whether a value is an integer. It is an alias of is_int(), so both functions give exactly the same result.

An integer is a whole number such as 7, 0 or -25. The check is strict about the type, so the float 3.0 and the string '42' are not integers even though they look like whole numbers. Most developers prefer the name is_int() in new code.

Syntax

Call is_long() with the values you need. Start with this line.

PHP
$ok = is_long($value);
CallWhat it does
is_long(42)Returns true because 42 is an integer.
is_long(3.0)Returns false because 3.0 is a float, not an integer.
is_long('42')Returns false because '42' is a string, even though it contains digits.

is_long() and is_integer() are both aliases of is_int(). Use is_int() in new code because it is the main name in the PHP manual. If you want to accept numeric strings, use is_numeric() instead.

Library declarations
PHP
is_long(mixed $value): bool

Parameters

ParameterDescription
valueRequired. The value you want to check. It can be of any type.

Return Value

Return ValueDescription
boolReturns true if the value is of type int, and false for every other type.

PHP Examples

Example 1 — Checking Whole Numbers

Pass positive, negative and zero values and see that all of them are integers.

PHP
<?php
var_dump(is_long(42));
var_dump(is_long(-7));
var_dump(is_long(0));

How It Works

  1. 42 is a whole number. PHP stores it as an int, so the result is true.
  2. -7 is a negative integer. The sign does not change the type, so it is also true.
  3. 0 is an integer too. Zero is a normal whole number, so the result is true.
  4. var_dump() shows the result as a real boolean. This makes it easy to see true and false.

Example 2 — Values That Are Not Integers

See which look-alike values return false, because their type is not int.

PHP
<?php
var_dump(is_long(3.0));
var_dump(is_long('42'));
var_dump(is_long(true));
var_dump(is_long(null));

How It Works

  1. 3. 0 is a float. It has a decimal point in its type, so is_long() returns false.
  2. '42' is a string. The quotes make it text, so the result is false.
  3. true is a boolean. PHP does not treat booleans as integers in this check.
  4. null is not a number at all. It means no value, so the result is false.

Example 3 — Same Result as is_int()

Loop over three values and compare is_long() with is_int() to prove that they are aliases.

PHP
<?php
$values = [10, 10.5, '10'];

foreach ($values as $v) {
    echo gettype($v), ': ';
    echo is_long($v) === is_int($v) ? 'same as is_int' : 'different', PHP_EOL;
}

How It Works

  1. The array holds three types. It has an int, a float and a string.
  2. gettype() prints the type name. PHP calls a float 'double' in this function.
  3. The comparison checks both functions. is_long($v) === is_int($v) is true when they agree.
  4. They always agree. Because is_long() is an alias, every line prints same as is_int.

Frequently Asked Questions

It checks whether a value is an integer. It returns true for values of type int and false for floats, strings, booleans, arrays, null and everything else.
Yes. is_long() is an alias of is_int(), so they behave in exactly the same way. The name is_int() is more common and is preferred in new code.
Because '42' is a string. is_long() checks the type of the value, not what it looks like. Use is_numeric() if you want to accept numeric strings.
No. 5.0 is a float, so is_long(5.0) returns false. You can convert it with (int) 5.0 if you need an integer.
No. It is still available as an alias and works in all PHP 8 versions. It is simply not the recommended name, so use is_int() when you write new code.

Next: is_null()

is_null() checks whether a variable is exactly null. It returns true only for the null val.

is_null() 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