PHP gettype() Function
gettype()The function is used to get the type of a variable.
Note: Do not usegettype()to test a certain type, because the string it returns may need to change in future versions. In addition, since it involves string comparison, it is also slower. Useis_*function instead.
Version requirements: PHP 4, PHP 5, PHP 7
Syntax
string gettype ( mixed $var )
Parameter description:
- $var: variable.
Return Value
Returns a string, possible values are:
- boolean
- integer
- double
- string
- array
- object
- resource
- NULL
- unknown type
Example
Example
echo gettype(102) . PHP_EOL;
echo gettype(true) . PHP_EOL;
echo gettype(' ') . PHP_EOL;
echo gettype(null) . PHP_EOL;
echo gettype(array()) . PHP_EOL;
echo gettype(new stdclass());
The output result is:
integer boolean string NULL array objectOther Extensions
PHP Available Functions