What is PHP is_long() Function?
If you want to know whether a variable is a scalar or not, use is_scalar() function.
Few important things about integer-
- An integer is a whole number, no decimal part included in it. Ex. 1,100000 etc.
- PHP supports signed integer i.e. it can be both positive or negative.
- You can define an integer in four formats –
- Decimal (10 based): Example- 100
- Hexadecimal (16 based, starts with 0x or 0X): Example- 0xA
- Octal (8 based, starts with 0o or 0O or 0): Example- 0o12
- Binary (2 based, starts with 0b or 0B): Example 0b1010
- Integer size is platform-dependent. Using the following constants, you can find out about your system’s integer support-
- PHP_INT_MAX: Largest possible integer value. In my system, it is 9223372036854775807.
- PHP_INT_MIN: Smallest possible integer value. In my system it is -9223372036854775808.
- PHP_INT_SIZE: Integer size in bytes. In my system, it is 8.
Syntax:
is_long(variable)
Parameters:
The Function has parameter which is required-
variable (Required): It specifies a value.
Return Values:
The function returns-
- TRUE –if the value is of integer type.
- FALSE – if the value is not of integer type.
Examples:
Example 1:
<?php
echo "Is 26 a long value? " . (is_long(26) ? 'Yes' : 'No') . "<br />";
echo "Is \"26\" a long value? " . (is_long("26") ? 'Yes' : 'No') . "<br />";
echo "Is 126.0 a integer value? " . (is_long(26.0) ? 'Yes' : 'No') . "<br />";
echo "Is \"PHP\" a long value? " . (is_long("PHP") ? 'Yes' : 'No') . "<br />";
echo "Is TRUE a long value? " . (is_long(TRUE) ? 'Yes' : 'No') . "<br />";
echo "Is [2, 6] a long value? " . (is_long([2, 6]) ? 'Yes' : 'No') . "<br />";
echo "Is NULL a long value? " . (is_long(NULL) ? 'Yes' : 'No');
?>
Output:
Is 26 a long value? Yes
Is "26" a long value? No
Is 126.0 a integer value? No
Is "PHP" a long value? No
Is TRUE a long value? No
Is [2, 6] a long value? No
Is NULL a long value? No
Practical Usages of is_long() Function:
- You can validate of integer type of form inputs with this function
- You can validate a integer value before inserting into database field which only accept integer value.
- When separating integers from other types of values from an array or files, you can use this function.
Notes on is_long() Function:
- is_long() is alias for the function is_int() function.
- Though, modern PHP supports integer() function, it is recommended to use the shorter one – int() function.
PHP Version Support:
PHP 4, PHP 5, PHP 7, PHP 8
Summary: PHP is_long() Function
is_long() is a built-in variable handling function. Use this function when you need strict type checking for a number value.