array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.gettype.php', 1 => 'gettype', ), 'up' => array ( 0 => 'ref.var.php', 1 => '变量处理函数', ), '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' => 'zh', '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 — 获取变量的类型
value
要检查类型的变量。
返回字符串,可能值为:
"boolean"
"integer"
"double"
(由于历史原因,如果是浮点型,则返回 "double"
,而不仅仅是 "float"
)
"string"
"array"
"object"
"resource"
"resource (closed)"
自 PHP 7.2.0 起
"NULL"
"unknown type"
版本 | 说明 |
---|---|
7.2.0 |
现在,已关闭的资源报告为 'resource (closed)' 。此前,已关闭的资源报告为
'unknown type' 。
|
示例 #1 gettype() 示例
<?php
$data = array(1, 1., NULL, new stdClass, 'foo');
foreach ($data as $value) {
echo gettype($value), "\n";
}
?>
以上示例的输出类似于:
integer double NULL object string