English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP gettype() function usage and example

PHP available functions

gettype() The function is used to get the type of a variable.

Note: Do not use gettype() To test a type, because the returned string may need to change in future versions. Moreover, since it includes string comparison, its execution is also slower. Use is_* Function alternative.

Version requirement: PHP 4, PHP 5, PHP 7

Syntax

string gettype ( mixed $var )

Parameter description:

  • $var: variable.

Return value

The returned string may be:

  • boolean
  • integer
  • double
  • string
  • array
  • object
  • resource
  • NULL
  • unknown type

Online 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());
?>

The output result is:

integer
boolean
string
NULL
array
object

PHP available functions