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

查看所有标签

Natural Language Processing with Python

Natural Language Processing with Python

Steven Bird、Ewan Klein、Edward Loper / O'Reilly Media / 2009-7-10 / USD 44.99

This book offers a highly accessible introduction to Natural Language Processing, the field that underpins a variety of language technologies, ranging from predictive text and email filtering to autom......一起来看看 《Natural Language Processing with Python》 这本书的介绍吧!

SHA 加密
SHA 加密

SHA 加密工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器