本站资源收集于互联网,不提供软件存储服务,每天免费更新优质的软件以及学习资源!

PHP函数中如何获取变量的类型信息?

网络教程 app 1℃

PHP函数中如何获取变量的类型信息

php 中获取变量类型的函数是 gettype(),它返回一个表示变量类型的字符串。返回的类型字符串可以是:布尔值、整形、浮点值、字符串、数组、对象、资源或 null。

PHP 函数中获取变量类型信息

在 PHP 中,我们可以使用 gettype() 函数来获取变量的类型信息。它返回一个字符串,表示变量的类型。

语法:

gettype(variable)

参数:

variable:要获取类型信息的变量。

返回值:

字符串,表示变量的类型。

类型字符串:

类型 字符串

布尔值boolean整形integer浮点值double字符串string数组array对象object资源resourceNULLNULL未定义undefined

实战案例:

<?php // 获取布尔值变量的类型$is_true = true;$type = gettype($is_true);echo "Variable ‘is_true’ is of type: $type";// 获取整形变量的类型$number = 123;$type = gettype($number);echo "Variable ‘number’ is of type: $type";?>

输出:

Variable ‘is_true’ is of type: booleanVariable ‘number’ is of type: integer

以上就是PHP 函数中如何获取变量的类型信息?的详细内容,更多请关注范的资源库其它相关文章!

转载请注明:范的资源库 » PHP函数中如何获取变量的类型信息?

喜欢 (0)