{php 数据类型}

转:

{php 数据类型}

PHP 支持8种基本的数据类型。

四种标量类型:

boolean (布尔型)
integer (整型)
float (浮点型, 也称作 double)
string (字符串)
两种复合类型:

array (数组)
object (对象)
最后是两种特殊类型:

resource (资源)
NULL (NULL)
为了确保代码的易读性,本手册还介绍了一些伪类型:

mixed
number
callback
以及伪变量 $....

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

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

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

如果只是想得到一个易读懂的类型的表达方式用于调试,用 gettype()。要查看某个类型,不要用 gettype(),而用 is_type 函数。以下是一些范例:
  1. <?php
  2. $a_bool = TRUE;   // a boolean
  3. $a_str  = "foo";  // a string
  4. $a_str2 = 'foo';  // a string
  5. $an_int = 12;     // an integer
  6. echo gettype($a_bool); // prints out:  booleane
  7. cho gettype($a_str);  // prints out:  string
  8. // If this is an integer, increment it by four
  9. if (is_int($an_int)) {   
  10. $an_int += 4;
  11. }
  12. // If $bool is a string, print it out
  13. // (does not print out anything)
  14. if (is_string($a_bool)) {
  15.    echo "String: $a_bool";
  16. }
  17. ?>
复制代码

作者: feiyang10086   发布时间: 2011-06-03

火速围观!牛人招PHP技术员-出得厅堂,下得厨房,进得洞房!有木有!!有木有!!

http://bbs.phpchina.com/thread-214382-1-1.html   这公司太有才了,做PHP的还要求会武功,找金庸大师学学吧,笑死俺了哈

作者: 个人平   发布时间: 2011-06-03