CancelImage Upload

How to check if a variable is an integer, double, string, array or object

Although this should usually not happen to an organised programmer, there may come a time with 30'000 plus lines of code, that a track is lost on a certain variable, and that a function is required to check what type of variable once was defined.

In PHP the variable to handle this kind of task is gettype(). In the following example for instance, get type will return the value string, as the variable defined contains a simple piece of text:


$string = "Hello World";

echo gettype($string);


While the above example returns string, the next one will return array, since an array has indeed been loaded into the variable $array:


$array = array(

"fruit" => "Apple",

"meat" => "Steak",

"vegetables" => "Beans"


echo gettype($array);


The same outcome would take place for variables defined as an integer, double or object.

Want to leave a comment?

No problem. Just enter your email and password below.

register | home | reminder

myDesignTool Networking •