Both of the functions looks similar, but there is a difference, which can screw your time if you’re not aware of it and using blindly! is_int() seems same to is_numeric(), checking the variable if it’s integer or not, but it’s not exactly what you’re thinking.
The key difference between these two functions is that is_int() checks the type of variable, while is_numeric() checks the value of the variable.
From PHP.net,
is_int: Find whether the type of a variable is integer
is_numeric: Finds whether a variable is a number or a numeric string
So, if you check something like:
$var = "123"; |
$var is a string of numbers, not an integer value.
Therefor is_int should return false as it’s not an integer, it’s a string.
However it is a numeric string, so hence is_numeric should return true.