PHP gettype() 函数

PHP 教程 · 2019-01-31 15:56:59

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

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

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

语法

string gettype ( mixed $var )

参数说明:

  • $var:变量。

返回值

返回字符串,可能值为:

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

实例

实例

<?php echo 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()); ?>

输出结果为:

integer
boolean
string
NULL
array
object

点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html

查看所有标签

The Hard Thing About Hard Things

The Hard Thing About Hard Things

Ben Horowitz / HarperBusiness / 2014-3-4 / USD 29.99

Ben Horowitz, cofounder of Andreessen Horowitz and one of Silicon Valley's most respected and experienced entrepreneurs, offers essential advice on building and running a startup—practical wisdom for ......一起来看看 《The Hard Thing About Hard Things》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码