超越PHP PHP动态 | 经典文章 | CLASS | 相关下载 | 常见问题 | FORUM | WIKI | 在线手册
Site search:    
<serializestrval>
Last updated: Fri, 22 Jun 2007

settype

(PHP 3, PHP 4 , PHP 5)

settype -- 设置变量的类型

描述

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

例子 1. settype() 示例

<?php
$foo
= "5bar"; // string
$bar = true// boolean

settype($foo, "integer"); // $foo 现在是 5  (integer)
settype($bar, "string");  // $bar 现在是 "1" (string)
?>

参见 gettype()类型转换类型戏法




add a note add a note User Contributed Notes
settype
jeffg at NOcounterintuitive dot orgSPAM
28-Oct-1999 05:46
It's worth noting that one can neither <I>settype()</i> nor type-cast a variable as a long.  The workaround for this seems to be to use <I>pack()</i>.

<serializestrval>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22