HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

gettype

Description

The gettype of Variable Handling for PHP get the type of a variable.

Syntax

gettype(
    mixed $value
): string

Parameters

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)