I have used
get_type($var)
But it always returns as string.. from the text box
echo "<input type='text' name='value'>";
I have used
get_type($var)
But it always returns as string.. from the text box
echo "<input type='text' name='value'>";
As per the documentation, it's gettype($var)
not get_type($var)
. Check the documentation for more.
You will always get strings from HTTP requests - as technically their params are passed as strings.
If you want to check whether a param (or any given value, in fact) is a numeric string, use is_numeric function:
var_dump(gettype('111')); // 'string'
var_dump(is_int('111')); // false - as it's a string, not an integer
var_dump(is_numeric('111')); // true - this string represents a number
var_dump(is_numeric('something')); // false - and this string doesn't
The function gettype()
should only be used to output the datatype of a variable. Testing for special datatypes – with this function – is not recommended, because the returns may change at some point. Instead, the functions is_boolean($var)
, is_string($var)
, is_float($var)
, is_array($var)
, is_object($var)
, is_resource($var)
and is_null($var)
should be used.
For more details : https://stackhowto.com/how-do-you-determine-the-data-type-of-a-variable-in-php/
You can use gettype();
to check datatype of variable in php.
However, the value of the input element of HTML is always wrapped into the string.
To convert string into number or other datatypes, there are a few ways to do so: you can see the solution for it here... https://stackoverflow.com/a/8529678/10743165