PHP gettype() | Find/Get Type of Variable

The PHP gettype() function is used when we need to find or get the type of a variable. For example:

<?php
   $x = 10;
   echo gettype($x), "<BR>";
   
   $x = 10.23;
   echo gettype($x), "<BR>";
   
   $x = "Hi, there!";
   echo gettype($x), "<BR>";
   
   $x = array("Berlin", "Munich", "Frankfurt");
   echo gettype($x), "<BR>";
   
   $x = false;
   echo gettype($x), "<BR>";
   
   $x = NULL;
   echo gettype($x), "<BR>";
   
   class myClass{
   }
   $x = new myClass();
   echo gettype($x), "<BR>";
?>

The output produced by above PHP example on using gettype() function to find and print the type of each variables, one by one, is shown in the snapshot given below:

php gettype function find type of variable

PHP gettype() Syntax

The syntax of gettype() function in PHP, is:

gettype(variable);

The variable parameter is required, refers to a variable, whose type we need to find.

PHP Online Test


« Previous Tutorial Next Tutorial »

Follow/Like Us on Facebook




Subscribe Us on YouTube