settype()

创建于 2024-12-03 / 35
字体: [默认] [大] [更大]

❮ PHP 变量处理参考

实例

将变量转换为特定类型:

<?php
$a = "32"; // string
settype($a, "integer"); // $a is now integer

$b = 32; // integer
settype($b, "string"); // $b is now string

$c = true; // boolean
settype($c, "integer"); // $c is now integer (1)
?> 亲自试一试 »

定义和用法

settype() 函数将变量转换为特定类型。


语法

settype(variable, type);

参数值

参数 描述
variable 必需。指定要转换的变量
类型 必需。指定变量要转换成的类型。 可能的类型有:boolean、bool、integer、int、float、double、string、array、object、null

技术细节

返回值: 成功为 TRUE,失败为 FALSE
返回类型: Boolean
PHP 版本: 4.0+

❮ PHP 变量处理参考
0 人点赞过