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。

实例

实例

<?php $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://codercto.com/courses/l/5.html

查看所有标签

Flexible Rails

Flexible Rails

Peter Armstrong / Manning Publications / 2008-01-23 / USD 44.99

Rails is a fantastic tool for web application development, but its Ajax-driven interfaces stop short of the richness you gain with a tool like Adobe Flex. Simply put, Flex is the most productive way t......一起来看看 《Flexible Rails》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具