PHP provides auto data type conversion so you can assign int value in the beginning and change it to float in the middle and PHP won't make a sound!
An integer data type is a non-decimal number between -2147483648 and 2147483647. So, any number out of that range is considered and stored as a float.
So, we need to be careful while assigning values in a lengthy program or calculation as the data type change can cause some errors.
Here are the functions we can use to check if the number is integer.
- is_int()
- is_integer()
- is_long()
To check whether the number is float use these following functions:
- is_float()
- is_double()
Now, the float has it's own limit as well. If the number is greater than the PHP_FLOAT_MAX than it's infinite number. We can check that using following functions.
- is_finite()
- is_infinite()
To check whether the value is not a number, use this
- is_nan()
Lastly, to check whether the variable is numeric or not, use following function
- PHP is_numeric()
float infinite integer NaN number variables