PHP Variable Handling is_long() Function



The PHP Variable Handling is_long() function is used to check that a given number is a long integer. It is a built-in function that can be used directly in your code. A long integer is a type of number without a decimal point. This function checks whether an integer is long before using it.

If the input is a long integer, the function returns true. If the input value is not a long integer, the function returns false. It is useful in programs that need us to use only complete numbers. With the help of is_long() function, we can avoid numerical errors.

Syntax

Below is the syntax of the PHP Variable Handling is_long() function −

bool is_long ( mixed $value )

Parameters

This function accepts $value parameter which is the number or variable needs to check for a long integer.

Return Value

The is_long() function returns TRUE if the value is a long integer. And it returns FALSE if the value is not a long integer.

PHP Version

First introduced in core PHP 4, the is_long() function continues to function easily in PHP 5, PHP 7, and PHP 8.

Example 1

Here is the basic example of the PHP Variable Handling is_long() function to check if a simple integer is a long integer. As the is_long() function is an alias of is_int() so it will return true.

<?php
   // An integer value
   $num = 100; 
   if (is_long($num)) {
      echo "$num is a long integer.";
   } else {
      echo "$num is not a long integer.";
   }
?>

Output

Here is the outcome of the following code −

100 is a long integer.

Example 2

In the below PHP code we will use the is_long() function and check a decimal number. As the is_long() function only returns true for integers so it will return false.

<?php
   // A floating-point number
   $num = 10.5; 
   if (is_long($num)) {
      echo "$num is a long integer.";
   } else {
      echo "$num is not a long integer.";
   }
?> 

Output

This will generate the below output −

10.5 is not a long integer.

Example 3

Now the below code demonstrates return values with different types of variables using the is_long() function.

<?php
   $a = 33;
   echo "a is "; var_dump(is_long($a)); 

   $b = "33";
   echo "b is "; var_dump(is_long($b)); 

   $c = 33.5;
   echo "c is "; var_dump(is_long($c)); 

   $d = "33.5";
   echo "d is "; var_dump(is_long($d)); 

   $e = true;
   echo "e is "; var_dump(is_long($e)); 

   $f = false;
   echo "f is "; var_dump(is_long($f)); 

   $g = null;
   echo "g is "; var_dump(is_long($g)); 
?> 

Output

This will create the below output −

a is bool(true)
b is bool(false)
c is bool(false)
d is bool(false)
e is bool(false)
f is bool(false)
g is bool(false)
php_variable_handling_functions.htm
Advertisements