The is_int() function is used to detect whether a variable is an integer.
Note: If you want to test whether a variable is a number or a string of numbers (such as form inputs, which are usually strings), you must use is_numeric() .
Alias function () : is_integer(), is_long().
PHP version requirements: PHP 4, PHP 5, PHP 7
grammar
bool is_int (mixed $var)
Parameter description:
$var: The variable to be tested.
return value
TRUE if the specified variable is an integer, FALSE otherwise.
Example
Example
<?php $var_name1 = 678 ; $var_name2 = " a678 " ; $ var_name3 = " 678 " ; $var_name4
= 999 ; $var_name5 = 698 .99 ; $var_name6 = array ( " a1 " , " a2 " ) ; $var_name7 =+ 125689 .66 ; if ( is_int ( $var_name1 ) ) { echo " $var_name1 is an integer " . PHP_EOL ; } else { echo " $var_name1 is not an integer " . PHP_EOL ; } if ( is_int ( $var_name2 ) ) { echo " $var_name2 is an integer " . PHP_EOL ; } else { echo " $var_name2 is not an integer " . PHP_EOL ; } $result = is_int ( $var_name3 ) ; echo " [ Is
$var_name3 an integer? ] " . var_dump ( $result ) . PHP_EOL ; $result = is_int ( $var_name4 ) ; echo " [ Is
$var_name4 an integer? ] " . var_dump ( $result ) . PHP_EOL ; $result = is_int ( $var_name5 ) ; echo " [ Is
$var_name5 an integer? ] " . var_dump ( $result ) . PHP_EOL ; $result = is_int ( $var_name6 ) ; echo " [ Is
$var_name6 an integer? ] " . var_dump ( $result ) . PHP_EOL ; $result = is_int ( $var_name7 ) ; echo " [ Is $var_name7 an integer? ]
" . var_dump ( $result ) ; ?> The output is:
678 is an integer a678 is not an integer bool(false)[ Is 678 an integer? ]bool(true)[ Is 999 an integer? ]bool(false)[ Is 698.99 an integer? ]bool(false)[ Is Array an integer? ] bool(false)[Is 125689.66 an integer? ]