Current Location: Home> Function Categories> gettype

gettype

Get the type of variable
Name:gettype
Category:Variable processing
Programming Language:php
One-line Description:Returns the type of the variable.

Definition and usage

gettype() function returns the type of the variable.

Example

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

Example explanation:

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" .

grammar

 gettype ( variable ) ;
parameter describe
variable Required. Specifies the variable to check.
Similar Functions
Popular Articles