PHP: Hypertext Preprocessor (original) (raw)

gettype

(PHP 4, PHP 5, PHP 7, PHP 8)

gettype — Get the type of a variable

Description

Parameters

value

The variable being type checked.

Return Values

Possible values for the returned string are:

Changelog

Version Description
7.2.0 Closed resources are now reported as 'resource (closed)'. Previously the returned value for closed resources were 'unknown type'.

Examples

Example #1 gettype() example

`<?php

$data

= array(1, 1., NULL, new stdClass, 'foo');

foreach ( dataasdata as dataasvalue) {
echo gettype($value), "\n";
}?>`

The above example will output something similar to:

integer double NULL object string

See Also

Found A Problem?

mohammad dot alavi1990 at gmail dot com

1 year ago

`Be careful comparing ReflectionParameter::getType() and gettype() as they will not return the same results for a given type.

string - string // OK
int - integer // Type mismatch
bool - boolean // Type mismatch
array - array // OK

`