Note that you can chain type castng:
var_dump((string)(int)false); //string(1) "0"
章 11. 类型介绍PHP 支持八种原始类型。 四种标量类型: 两种复合类型: 最后是两种特殊类型: 为了确保代码的易读性,本手册还介绍了一些伪类型: 可能还会读到一些关于“双精度(double)”类型的参考。实际上 double 和 float 是相同的,由于一些历史的原因,这两个名称同时存在。变量的类型通常不是由程序员设定的,确切地说,是由 PHP 根据该变量使用的上下文在运行时决定的。
如果要将一个变量强制转换为某类型,可以对其使用强制转换或者 settype() 函数。 注意变量根据其当时的类型在特定场合下会表现出不同的值。更多信息见类型戏法。此外,你还可以参考 PHP 类型比较表看不同类型相互比较的例子。
add a note
User Contributed Notes
arjini at gmail dot com
07-Dec-2005 04:32
Note that you can chain type castng:
shahnaz khan
18-Mar-2005 08:40
if we use gettype() before initializinf any variable it give NULL
Trizor of www.freedom-uplink.org
30-Jun-2004 09:14
The differance of float and double dates back to a FORTRAN standard. In FORTRAN Variables aren't as loosly written as in PHP and you had to define variable types(OH NOES!). FLOAT or REAL*4 (For all you VAX people out there) defined the variable as a standard precision floating point, with 4 bytes of memory allocated to it. DOUBLE PRECISION or REAL*8 (Again for the VAX) was identical to FLOAT or REAL*4, but with an 8 byte allocation of memory instead of a 4 byte allocation.
philip at cornado dot com
06-Jun-2001 03:02
To see if something is numeric (a number) then use is_numeric(). All form data is returned as strings so checking a form value as an integer will return false.
| |||