PHP

How to detect the data type of a PHP variable

Written by Ian Carnaghan · 10 sec read >

The data type of a PHP variable can be detected by using the built-in PHP functiongettype() (PHP 4, PHP 5)

Example:

$var ="This is a sentence"

echo $var; //This will return "string"

The following possible values can be returned:

  • boolean
  • integer
  • double
  • string
  • array
  • object
  • resource
  • NULL
  • unknown type

Last Updated On March 22, 2018
Written by Ian Carnaghan
I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment. In my spare time I teach undergraduate classes in web development. Profile

Leave a Reply

avatar
  Subscribe  
Notify of