English
欢迎访问www.CanadaSky.com,本站快捷网址:www.caSky.com
本站免费二级域名:YourName.caSky.com
帮助信息 服务条款
网站简介 隐私保护
客户服务 联系我们
免费注册 忘记密码
电脑技术文档索引 Red Hat Linux 9 设置指南 Red Hat Linux 9 入门指南 Red Hat Linux 9 安装指南 FreeBSD中文参考手册
PHP参考手册 Apache 2 中文参考手册 MySQL4.1中文参考手册 QMail中文参考手册 PostgreSQL 8.0.0 中文文档

类型

章 6. 类型

介绍

PHP 支持八种原始类型。

四种标量类型:

  • 布尔型(boolean)

  • 整型(integer)

  • 浮点型(float)(浮点数,也作“double”)

  • 字符串(string)

两种复合类型:

  • 数组(array)

  • 对象(object)

最后是两种特殊类型:

  • 资源(resource)

  • NULL

为了确保代码的易读性,本手册还介绍了一些伪类型

您可能还会读到一些关于“双精度(double)”类型的参考。实际上 double 和 float 是相同的,由于一些历史的原因,这两个名称同时存在。

变量的类型通常不是由程序员设定的,确切地说,是由 PHP 根据该变量使用的上下文在运行时决定的。

注: 如果你想查看某个表达式的值和类型,用 var_dump()

注: 如果你只是想得到一个易读懂的类型的表达方式用于调试,用 gettype()。要查看某个类型,不要gettype(),而用 is_type 函数。以下是一些范例:

<?php
$bool
= TRUE;   // a boolean
$str  = "foo";  // a string
$int  = 12;     // an integer

echo gettype($bool); // prints out "boolean"
echo gettype($str);  // prints out "string"

// If this is an integer, increment it by four
if (is_int($int)) {
    
$int += 4;
}

// If $bool is a string, print it out
// (does not print out anything)
if (is_string($bool)) {
    echo
"String: $bool";
}
?>

如果你要将一个变量强制转换为某类型,可以对其使用强制转换或者 settype() 函数。

注意变量根据其当时的类型在特定场合下会表现出不同的值。更多信息见类型戏法。此外,你还可以参考 PHP 类型比较表看不同类型相互比较的例子。



自动支持 1024x768 和 800x600 最佳页面显示效果, 请使用IE4.0以上浏览器浏览本站
版权所有© 2002-2005 加拿大晴空网 网站简介 帮助信息 服务条款 隐私保护 广告业务 客户服务 联系我们