gettype
Get the type of variable
gettype()
function returns the type of the variable.
Returns the types 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
gettype()
function is used to check different types of variables (integral, floating point, string, array, null, and boolean) and return their types. For example, for the integer variable $a
, gettype($a)
will return the string "integer"
. For the floating point variable $b
it will return "double"
, for the string variable $c
it will return "string"
, and so on. If the variable is a closed resource, in PHP 7.2 and later, gettype()
returns "resource (closed)"
and in earlier versions it might return "unknown type"
. gettype ( variable ) ;
parameter | describe |
---|---|
variable | Required. Specifies the variable to check. |