PHP settype() 函数

定义和用法

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

实例

将变量转换为特定类型:

<?php
$a = "32"; // string
settype($a, "integer"); // $a 现在是整数

$b = 32; // integer
settype($b, "string"); // $b 现在是字符串 

$c = true; // boolean
settype($c, "integer"); // $c 现在是整数 (1)
?>

亲自试一试

语法

settype(variable, type);
参数 描述
variable 必需。指定要转换的变量。
type

必需的。指定要将变量转换为的类型。可能的类型有:

  • boolean
  • bool
  • integer
  • int
  • float
  • double
  • string
  • array
  • object
  • null

技术细节

返回值: 成功时返回 TRUE,失败时返回 FALSE。
返回类型: 布尔值
PHP 版本: 4.0+