settype
(PHP 4, PHP 5, PHP 7, PHP 8)
settype — 设置变量的类型
参数
var-
要转换的变量。
type-
type的可能值为:- “boolean”或“bool”
- “integer”或“int”
- “float”或“double”
- "string"
- "array"
- "object"
- “null”
示例
示例 #1 settype() 示例
<?php
$foo = "5bar"; // string
$bar = true; // boolean
settype($foo, "integer"); // $foo 现在是 5 (integer)
settype($bar, "string"); // $bar 现在是 "1" (string)
var_dump($foo, $bar);
?>注释
注意:
“int”的最大值是
PHP_INT_MAX。