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://www.codercto.com/courses/l/5.html

查看所有标签

Beginning Apache Struts

Beginning Apache Struts

Arnold Doray / Apress / 2006-02-20 / USD 44.99

Beginning Apache Struts will provide you a working knowledge of Apache Struts 1.2. This book is ideal for you Java programmers who have some JSP familiarity, but little or no prior experience with Ser......一起来看看 《Beginning Apache Struts》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

html转js在线工具
html转js在线工具

html转js在线工具