array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'es', ), 'this' => array ( 0 => 'function.gettype.php', 1 => 'gettype', ), 'up' => array ( 0 => 'ref.var.php', 1 => 'Funciones de manejo de variables', ), 'prev' => array ( 0 => 'function.get-resource-type.php', 1 => 'get_resource_type', ), 'next' => array ( 0 => 'function.intval.php', 1 => 'intval', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'es', 'path' => 'reference/var/functions/gettype.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
gettype — Obtener el tipo de una variable
Devuelve el tipo de la variable PHP var
. Para
la comprobación de tipos, utilice las funciones is_*
.
var
La variable de la cual queremos comprobar su tipo.
Los valores posibles para la cadena devuelta son:
Ejemplo #1 Ejemplo de gettype()
<?php
$data = array(1, 1., NULL, new stdClass, 'foo');
foreach ($data as $value) {
echo gettype($value), "\n";
}
?>
El resultado del ejemplo sería algo similar a:
integer double NULL object string