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";
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"
The same outcome would take place for variables defined as an integer, double or object.