What is the is_integer method in PHP?
The is_integer method checks if the type of variable is an integer.
Syntax
is_integer(mixed $value): bool
Parameter
value: the variable to evaluate.
Return value
This method returns true if the passed value is an integer type. Otherwise, it returns false.
Code
<?php$test = 10;printIsInteger($test);$test = 10000;printIsInteger($test);$test = 100.1;printIsInteger($test);$test = '10';printIsInteger($test);function printIsInteger($test){echo "The Value is: ";var_dump($test);echo "Is Integer: ";var_dump(is_integer($test));echo "---------\n\n";}?>
Explanation
In the code above:
-
We have used the
is_integermethod to check if a variable is an integer. -
The
is_integermethod returnstruefor the value10and10000. -
The
is_integermethod returnsfalsefor the values100.1and10because they arefloatandstringtypes respectively.