gettype
Description
The gettype of Variable Handling for PHP get the type of a variable.
Syntax
gettype(
mixed $value
): stringParameters
value
The variable being type checked.
Return
Possible values for the returned string:
| String |
|---|
| boolean |
| integer |
| double (for historical reasons in case of a float, "double" is returned and not "float") |
| string |
| array |
| object |
| resource |
| resource (closed) |
| NULL |
Examples
1 · value · single
<? $value = false; $return = gettype($value); echo $return;
boolean
2 · value · multiple
<?
$array = array(
false,
0,
12.34,
"abc",
array(1, 2, 3),
new stdclass,
null
);
foreach($array as $value)
{
$return = gettype($value);
echo $return . PHP_EOL;
}
boolean integer double string array object NULL
3 · resource
<?
$filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/txt/1.txt';
$mode = 'r';
$value = fopen($filename, $mode);
$return = gettype($value);
echo $return;
fclose($value);
resource
4 · resource (closed)
<? $filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/txt/1.txt'; $mode = 'r'; $value = fopen($filename, $mode); fclose($value); $return = gettype($value); echo $return;
resource (closed)
Links
Variable Handling
- boolval
- debug_zval_dump
- doubleval
- empty
- floatval
- get_debug_type
- get_defined_vars
- get_resource_id
- get_resource_type
- intval
- is_array
- is_bool
- is_callable
- is_countable
- is_double
- is_float
- is_int
- is_integer
- is_iterable
- is_long
- is_null
- is_numeric
- is_object
- is_real
- is_resource
- is_scalar
- is_string
- isset
- print_r
- serialize
- settype
- strval
- unserialize
- unset
- var_dump
- var_export