您当前的位置:首页 > 网站建设 > php
| php | asp | css | H5 | javascript | Mysql | Dreamweaver | Delphi | 网站维护 | 帝国cms | React | 考试系统 | ajax | jQuery |

PHP gettype() 函数

51自学网 2023-01-07 20:26:41
  php

gettype() 函数用于获取变量的类型。

注意:不要使用 gettype() 来测试某种类型,因为其返回的字符串在未来的版本中可能需要改变。此外,由于包含了字符串的比较,它的运行也是较慢的。使用 is_* 函数代替。

版本要求:PHP 4, PHP 5, PHP 7

语法

string gettype ( mixed $var )

参数说明:

  • $var:变量。

返回值

返回字符串,可能值为:

  • boolean
  • integer
  • double
  • string
  • array
  • object
  • resource
  • NULL
  • unknown type

实例

实例

<?phpecho gettype(102) . PHP_EOL;echo gettype(true) . PHP_EOL;echo gettype(' ') . PHP_EOL;echo gettype(null) . PHP_EOL;echo gettype(array()) . PHP_EOL;echo gettype(new stdclass());?>

输出结果为:

integerbooleanstringNULLarrayobject

下载地址:
PHP get_resource_type() 函数
PHP import_request_variables() 函数
51自学网,即我要自学网,自学EXCEL、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。
京ICP备13026421号-1