PHP settype() 函数
PHP 教程
· 2019-01-31 21:28:59
settype() 函数用于设置变量的类型。
PHP 版本要求: PHP 4, PHP 5, PHP 7
语法
bool settype ( mixed &$var , string $type )
参数说明:
$var: 要转换的变量。
$type: type 的可能值为。
- "boolean" (或为"bool",从 PHP 4.2.0 起)
- "integer" (或为"int",从 PHP 4.2.0 起)
- "float" (只在 PHP 4.2.0 之后可以使用,对于旧版本中使用的"double"现已停用)
- "string"
- "array"
- "object"
- "null" (从 PHP 4.2.0 起)
返回值
设置成功时返回 TRUE, 失败时返回 FALSE。
实例
实例
$foo = "5bar"; // string
$bar = true; // boolean
var_dump($foo);
var_dump($bar);
settype($foo, "integer"); // $foo 现在是 5 (integer)
settype($bar, "string"); // $bar 现在是 "1" (string)
var_dump($foo);
var_dump($bar);
输出结果为:
string(4) "5bar" bool(true) int(5) string(1) "1"
点击查看所有 PHP 教程 文章: https://www.codercto.com/courses/l/5.html
The Art and Science of Java
Eric Roberts / Addison-Wesley / 2007-3-1 / USD 121.60
In The Art and Science of Java, Stanford professor and well-known leader in CS Education Eric Roberts emphasizes the student-friendly exposition that led to the success of The Art and Science of C. By......一起来看看 《The Art and Science of Java》 这本书的介绍吧!