Home  >  Article  >  Backend Development  >  How to check variable type in php

How to check variable type in php

王林
王林Original
2020-08-20 14:26:024967browse

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.

How to check variable type in php

#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(&#39; &#39;) . 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn