gettype
Returns the name of a value's type.
Syntax
gettype(mixed $value): stringParameters
| Parameter | Type | Description |
|---|---|---|
| $value | mixed | Any value. |
Return value
stringThe type name: `integer`, `double`, `string`, `boolean`, `array`, `object`, `NULL`.
Examples
The types of different values:
<?php
echo gettype(42), "\n";
echo gettype(4.5), "\n";
echo gettype('text'), "\n";
echo gettype([1, 2]);Output:
integer
double
string
arrayThe more modern get_debug_type():
<?php
echo get_debug_type(4.5), ' ', get_debug_type(true), ' ', get_debug_type(new DateTime());Output:
float bool DateTimeNotes
The names from gettype() are historical: double rather than float, integer rather than int. get_debug_type() returns the familiar names and the class name for objects.
See also
- var_dump — Prints the type and the value — for debugging.
- is_array — Checks whether a value is an array.
- is_numeric — Checks whether a value is a number or a numeric string.
In the tutorial
- Data types — The main PHP data types — strings, numbers, booleans, arrays and null.