Home > Article > Backend Development > How to use PHP gettype()
In PHP, the gettype() function can obtain the type of a variable and is used to check the type of an existing variable. The syntax format is "gettype (variable name)"; the return value is boolean, integer, double, string, array , object, resource, NULL, etc.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
gettype() function is a built-in function in PHP Function that gets the type of a variable; it is used to check the type of an existing variable.
Syntax
string gettype ( mixed $var )
Parameters: This function accepts a single parameter $var. It is the variable name whose type needs to be checked.
Return value: This function returns a string type value. Possible values for the returned string are:
boolean
integer
double
string
Example:
<?php $var1 = true; // boolean value $var2 = 3; // integer value $var3 = 5.6; // double value $var4 = "Abc3462"; // string value $var5 = array(1, 2, 3); // array value $var6 = new stdClass; // object value $var7 = NULL; // null value $var8 = tmpfile(); // resource value echo gettype($var1)."<br>"; echo gettype($var2)."<br>"; echo gettype($var3)."<br>"; echo gettype($var4)."<br>"; echo gettype($var5)."<br>"; echo gettype($var6)."<br>"; echo gettype($var7)."<br>"; echo gettype($var8)."<br>"; ?>Output:
boolean integer double string array object NULL resourceRecommended learning: "
PHP Video Tutorial"
The above is the detailed content of How to use PHP gettype(). For more information, please follow other related articles on the PHP Chinese website!