PHP gettype() Function

❮ PHP Variable Handling Reference

Example

Return the type of different variables:

<?php
$a = 3;
echo gettype($a) . "<br>";

$b = 3.2;
echo gettype($b) . "<br>";

$c = "Hello";
echo gettype($c) . "<br>";

$d = array();
echo gettype($d) . "<br>";

$e = array("red", "green", "blue");
echo gettype($e) . "<br>";

$f = NULL;
echo gettype($f) . "<br>";

$g = false;
echo gettype($g) . "<br>";
?>
Try it Yourself »

Definition and Usage

The gettype() function returns the type of a variable.


Syntax

gettype(variable);

Parameter Values

Parameter Description
variable Required. Specifies the variable to check

Technical Details

Return Value: The type as a string. Can be one of the following values: "boolean", "integer", "double", "string", "array", "object", "resource", "NULL", "unknown type"
Return Type: String
PHP Version: 4.0+
PHP Changelog: PHP 7.2: Closed resources are now returned as "resource (closed)". Earlier, the returned value was "unknown type".

❮ PHP Variable Handling Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.