settype

(PHP 4, PHP 5, PHP 7, PHP 8)

settype设置变量的类型

说明

settype(mixed &$var, string $type): bool

将变量 var 的类型设置成 type

参数

var

要转换的变量。

type

type 的可能值为:

  • “boolean”或“bool”
  • “integer”或“int”
  • “float”或“double”
  • "string"
  • "array"
  • "object"
  • “null”

返回值

成功时返回 true, 或者在失败时返回 false

范例

示例 #1 settype() 示例

<?php
$foo
= "5bar"; // string
$bar = true; // boolean

settype($foo, "integer"); // $foo 现在是 5 (integer)
settype($bar, "string"); // $bar 现在是 "1" (string)
?>

注释

注意:

“int”的最小值是 PHP_INT_MAX

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top