Home  >  Article  >  Backend Development  >  How to use PHP gettype()

How to use PHP gettype()

青灯夜游
青灯夜游Original
2021-07-08 17:34:522218browse

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.

How to use PHP gettype()

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

  • ##array

  • object

  • resource

  • NULL

  • unknown type

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
resource

Recommended 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!

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