Skip to content

Getting the variable type

Get variable type: gettype()

If you have a variable and you need to detect the type (β€œstring”, β€œinteger”, β€œboolean”, …) you can use the gettype() function. It returns a string with the name of the type.

// gettype of 1 is an integer
echo gettype(1) . PHP_EOL; // "integer"
//gettype of "1" is a string
echo gettype("1") . PHP_EOL; // "string"

It works also with array, object and resources (file opened or closed).