PHP gettype

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

PHP : gettype() function

Description

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

Version

(PHP 4 and above)

Syntax

gettype(var_name)

Parameter

Name

Description

Required /
Optional

Type

var_name

The name of the variable.

Required

Mixed*

*Mixed : Mixed indicates that a parameter may accept multiple (but not necessarily all) types.

Return value

Possible values of the returned string :

  • boolean

  • integer

  • double

  • string

  • array

  • object

  • resource

  • NULL

  • unknown type

 

Pictorial presentation of PHP gettype() function

Pictorial presentation of PHP gettype() function

Example :

  1. echo gettype(102).'
    ';  

  2. echo gettype(true).'
    ';  

  3. echo gettype(' ').'
    ';  

  4. echo gettype(null).'
    ';  

  5. echo gettype(array()).'
    ';  

  6. echo gettype(new stdclass());  

  7. ?>  

Output :

integer
boolean
string
NULL
array
object