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

查看所有标签

The Web Application Hacker's Handbook

The Web Application Hacker's Handbook

Dafydd Stuttard、Marcus Pinto / Wiley / 2011-9-27 / USD 50.00

The highly successful security book returns with a new edition, completely updated Web applications are the front door to most organizations, exposing them to attacks that may disclose personal infor......一起来看看 《The Web Application Hacker's Handbook》 这本书的介绍吧!

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具

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

HEX CMYK 互转工具