请问,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的对象比较介绍 mvc架构适合用在商城系统吗? 数组求助? 用循环读出数据库数据,为什么没数据的字段,单元格会没有边边? 关于列表中某一个记录提前或者置后的实现方法的提问 PostgreSQL下limit查询的问题。急! 有没有办法实现编程实现 定时自动对论坛某个板块发帖 关于gd库问题,ice_berg16(寻梦的稻草人)请进,是你写的类!! 如何改变默认访问的主页?在线等,谢谢! 紧急求助!!位什么我的php不能解释表单传递过来的变量???载线等待!! 关于PHP调用javabean的问题,哪位仁兄有这方面经验?? 进入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?
这个是手册上的例子