Variable type

Apart from the getype() function in PHP, is there any more function, which can also return the variable type.

gettype() is a specialized tool. It does what it promises and returns a variable’s type.
var_dump() also tells you a variable’s type with that it also tells you contents it is holding. More than that, for complex types such as arrays and objects, var_dump() provides information about all the types contained within the variable, as well as about the variable itself.

$test = 5;
var_dump( $test );

This fragment gives us the following result:


This tells us that the variable $test contains an integer and that the value of that integer is 5.

With var_dump() we did not need print to print the the result because the function prints its findings directly to the browser or command line.

but, with the gettype(), we do need to use the print statement:
print gettype(test);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.