The function gettype() returns type of a variable.
string gettype ( mixed $value )
Sr.No | Parameter & Description |
---|---|
1 |
value The variable whose type will be checked. *mixed: mixed indicates that a parameter may accept multiple (but not necessarily all) types |
This function returns a string. Possible values for the returned string are −
boolean
integer
double (for historical reasons double is returned in case of a float, and not simply float)
string
array
object
resource
resource (closed) (as of PHP 7.2.0)
NULL
unknown type
PHP 4.0 and above
Following example demonstrates the use of gettype() for different types of variables −
<?php $data = array(2, 2.0, NULL, new stdClass, 'tutPoint', true, array(1, 2, 3), tmpfile()); foreach ($data as $value) { echo gettype($value); } ?>
This will produce following result −
integer double NULL object string boolean array resource