请问,php中==和===有什么区别? ===会比较两个变量的类型~~而==只比较他们的值~~~比如整数0和浮点数0.0用==比较返回TRUE用===比较返回FLASE 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $a == $b : $a 等于 $b$a === $b:$a 等于 $b,+++++++++++++并且它们的类型也相同 <?echo '<br>';echo ("007" == "7" ? "EQUAL" : "not equal");// Prints: EQUALecho '<br>';// Surrounding the strings with single quotes (') instead of double// quotes (") to ensure the contents aren't evaluated, and forcing// string types has no effect.echo ( (string)'0001' == (string)'+1.' ? "EQUAL" : "not equal");// Prints: EQUALecho '<br>';// Including non-digit characters (like leading spaces, "e", the plus// or minus sign, period, ...) can still result in this behavior, if// a string happens to be valid scientific notation.echo (' 131e-2' == '001.3100' ? "EQUAL" : "not equal");// Prints: EQUAL// Same examples as above, using === instead of ==echo '<br>';echo ("007" === "7" ? "EQUAL" : "not equal");// Prints: not equalecho '<br>';echo ( (string)'0001' === (string)'+1.' ? "EQUAL" : "not equal");// Prints: not equalecho '<br>';echo (' 131e-2' === '001.3100' ? "EQUAL" : "not equal");// Prints: not equal?> 明白否? 再仔细看了看手册和上面的例子。Php5的我明白了,php4的就不明白了上面说的好像都是php5的标准阿 例子 13-2. PHP 4 中复合对象的比较<?phpclass FlagSet { var $set; function FlagSet($flagArr = array()) { $this->set = $flagArr; } function addFlag($name, $flag) { $this->set[$name] = $flag; } function removeFlag($name) { if (array_key_exists($name, $this->set)) { unset($this->set[$name]); } }}$u = new FlagSet();$u->addFlag('flag1', $o);$u->addFlag('flag2', $p);$v = new FlagSet(array('flag1'=>$q, 'flag2'=>$p));$w = new FlagSet(array('flag1'=>$q));echo "\nComposite objects u(o,p) and v(q,p)\n";compareObjects($u, $v);echo "\nu(o,p) and w(q)\n";compareObjects($u, $w);?> 我们得到预期的结果: Composite objects u(o,p) and v(q,p)o1 == o2 : TRUEo1 != o2 : FALSEo1 === o2 : TRUEo1 !== o2 : FALSEu(o,p) and w(q)o1 == o2 : FALSEo1 != o2 : TRUEo1 === o2 : FALSEo1 !== o2 : TRUE 问:u为什么==v?这个是手册上的例子 我上面是手册关于php4的对象比较介绍 php_error.log 文件超大是怎么回事? 不知道有没有人用过“网博士智能建站系统"?怎么样? mysql#2002 error 找不到原因 十万火急:为什么我写的上传图片函数在本机测试正常,到服务器上不行? 这个函数是干什么用的? 新人 网上的验证码例子里都是用Session,如果用cookie做验证码是否可行,与session相比哪个好? 怎么用正则表达式判断手机的正确? 询问一个关于PHP.INI中设置的一个菜问题...... 如何得到今天星期几?? php的fopen问题 进入discuz论坛管理界面后为何没有显示? 如何通过数据在PHP中画出走势图
$a === $b:$a 等于 $b,+++++++++++++并且它们的类型也相同
echo '<br>';
echo ("007" == "7" ? "EQUAL" : "not equal");
// Prints: EQUAL
echo '<br>';
// Surrounding the strings with single quotes (') instead of double
// quotes (") to ensure the contents aren't evaluated, and forcing
// string types has no effect.
echo ( (string)'0001' == (string)'+1.' ? "EQUAL" : "not equal");
// Prints: EQUAL
echo '<br>';
// Including non-digit characters (like leading spaces, "e", the plus
// or minus sign, period, ...) can still result in this behavior, if
// a string happens to be valid scientific notation.
echo (' 131e-2' == '001.3100' ? "EQUAL" : "not equal");
// Prints: EQUAL
// Same examples as above, using === instead of ==
echo '<br>';
echo ("007" === "7" ? "EQUAL" : "not equal");
// Prints: not equal
echo '<br>';
echo ( (string)'0001' === (string)'+1.' ? "EQUAL" : "not equal");
// Prints: not equal
echo '<br>';
echo (' 131e-2' === '001.3100' ? "EQUAL" : "not equal");
// Prints: not equal?> 明白否?
class FlagSet {
var $set; function FlagSet($flagArr = array()) {
$this->set = $flagArr;
} function addFlag($name, $flag) {
$this->set[$name] = $flag;
} function removeFlag($name) {
if (array_key_exists($name, $this->set)) {
unset($this->set[$name]);
}
}
}
$u = new FlagSet();
$u->addFlag('flag1', $o);
$u->addFlag('flag2', $p);
$v = new FlagSet(array('flag1'=>$q, 'flag2'=>$p));
$w = new FlagSet(array('flag1'=>$q));echo "\nComposite objects u(o,p) and v(q,p)\n";
compareObjects($u, $v);echo "\nu(o,p) and w(q)\n";
compareObjects($u, $w);
?>
我们得到预期的结果: Composite objects u(o,p) and v(q,p)
o1 == o2 : TRUE
o1 != o2 : FALSE
o1 === o2 : TRUE
o1 !== o2 : FALSEu(o,p) and w(q)
o1 == o2 : FALSE
o1 != o2 : TRUE
o1 === o2 : FALSE
o1 !== o2 : TRUE
问:u为什么==v?
这个是手册上的例子