gettype
(PHP 4, PHP 5, PHP 7)
gettype — Get the type of a variable
Description
Returns the type of the PHP variable var
. For
type checking, use is_* functions.
Return Values
Possible values for the returned string are:
Examples
Example #1 gettype() example
<?php
$data = array(1, 1., NULL, new stdClass, 'foo');
foreach ($data as $value) {
echo gettype($value), "\n";
}
?>
The above example will output something similar to:
integer double NULL object string
Changelog
Version | Description |
---|---|
7.2.0 | Closed resources are now reported as 'resource (closed)'. Previously the returned value for closed resources were 'unknown type'. |
See Also
- settype() - Set the type of a variable
- get_class() - Returns the name of the class of an object
- is_array() - Finds whether a variable is an array
- is_bool() - Finds out whether a variable is a boolean
- is_callable() - Verify that the contents of a variable can be called as a function
- is_float() - Finds whether the type of a variable is float
- is_int() - Find whether the type of a variable is integer
- is_null() - Finds whether a variable is NULL
- is_numeric() - Finds whether a variable is a number or a numeric string
- is_object() - Finds whether a variable is an object
- is_resource() - Finds whether a variable is a resource
- is_scalar() - Finds whether a variable is a scalar
- is_string() - Find whether the type of a variable is string
- function_exists() - Return TRUE if the given function has been defined
- method_exists() - Checks if the class method exists
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-function.gettype.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.