How to check the variable type in php: You can use the gettype() function to get the type of the variable. The specific usage method is: [gettype(new stdclass())], which indicates whether it is an object type.
#gettype() function is used to get the type of a variable.
(Recommended tutorial: php graphic tutorial)
Note: Do not use gettype() to test a certain type, because the string it returns will not be used in future versions may need to be changed. In addition, it runs slower due to the inclusion of string comparisons. Use the is_* functions instead.
Grammar:
string gettype ( mixed $var )
(Video tutorial recommendation: php video tutorial)
Example:
<?php 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()); ?>
Output results :
integer boolean string NULL array object
The above is the detailed content of How to check variable type in php. For more information, please follow other related articles on the PHP Chinese website!