有人可以解释这些语句中null是如何映射的吗?null与PHP < and >运算符
null>0; //=> bool(false)
null<0; //=> bool(false)
null==0; //=> bool(true)
但
null<-1; // => bool(true)
我以为这是一些映射问题,但无法破解它。
用Suhosin-Patch试用PHP 5.3.5-1。
有人可以解释这些语句中null是如何映射的吗?null与PHP < and >运算符
null>0; //=> bool(false)
null<0; //=> bool(false)
null==0; //=> bool(true)
但
null<-1; // => bool(true)
我以为这是一些映射问题,但无法破解它。
用Suhosin-Patch试用PHP 5.3.5-1。
我想指出你几个页面: http://php.net/manual/en/types.comparisons.php http://php.net/manual/en/language.operators.comparison.php http://php.net/manual/en/language.types.boolean.php
因此,在您的最后一个例子:
null<-1 => bool(true)
的null
被转换为false
和-1
被转换为true
, false
小于true
在你的前两个例子null
被转换为false
和0
被转换为false
,false
不小于或大于false
更高,但是等于它。
噢null
的乐趣! :D
需要澄清:D,非常好奇为什么null会在bool而不是(int) (int)在<的另一侧 – 2011-04-18 13:25:44
呃,你在做什么?所有这些陈述都是有效的。 – Khez 2011-04-11 16:02:25
如果你想要的准确性,使用'==='类型检查相等性 – JohnP 2011-04-11 16:07:40
如果只有PHP的null类似于SQL null ... – 2011-04-11 17:31:37