By using this function, we can check the input variable is integer or not. This function was introduced in PHP 4.0.
bool is_int (mixed $var)
Parameter | Description | Is compulsory |
---|---|---|
var_name | The variable being checked. | compulsory |
This function returns true if var_name is an integer, Otherwise false.
<?php $x=123; echo is_int($x); ?>
Output:
<?php $x = 56; $y = "xyz"; if (is_int($x)) { echo "$x is Integer \n" ; } else { echo "$x is not an Integer \n" ; } if (is_int($y)) { echo "$y is Integer \n" ; } else { echo "$y is not Integer \n" ; } ?>
Output:
<?php $check = 12345; if( is_int($check )) { echo $check . " is an int!"; } else { echo $check . " is not an int!"; } ?>
Output: