php等号(==)与全等(===)
header("content-type:text/html;charset=utf-8");
$person001=new Person("wuxifu", 110);
$person002=new Person("wuxifu", 110);
$person003=$person001;
//全等(===)判断首先要数据类型要一样,数据类型不一样就为false
//(1)是同一数据类型后,如果是对象(如果是同一对象则为true否者为false)
echo "
person001与person002不是同一对象的情况下,不全等*************
";
if($person001===$person002)
{
echo "person001===person002是同一对象";
}else
{
echo "person001!==person002不是同一对象";
}
echo "
person001与person003是同一对象的情况下,全等**************
";
if($person001===$person003)
{
echo "person001===person003是同一对象";
}else
{
echo "person001!==person003不是同一对象";
}
//(2)是同一数据类型后,如果是数组(如果内容一样则为true否者为false)
$array=array(110,120,130);
$array2=array(110,120,130);
$array3=$array;
echo "
array与array2不是同一数组,但内容一样,全等*************
";
if($array===$array2)
{
echo "array===array2";
}else
{
echo "array!==array2";
}
echo "
array与array3不是同一数组,但内容一样,全等************************
";
if($array===$array3)
{
echo "array===array3";
}else
{
echo "array!==array3";
}
echo "
array与array3不是同一数组,内容也不一样,不全等***********************
";
$array3[0]=0;
if($array===$array3)
{
echo "array===array3";
}else
{
echo "array!==array3";
}
echo "
";
//(3)是同一数据类型后,如果是四种标量类型(boolean,integer,float,string),值一样则为true否者为false
echo "
是同一数据类型后,如果是四种标量类型(boolean,integer,float,string),值一样则为true否者为false
";
$nums=110;
$nums2=120;
$nums3=110;
if($nums===$nums2)
{
echo "nums===nums2值一样";
}else
{
echo "nums!==nums2值不一样";
}
echo "
";
if($nums===$nums3)
{
echo "nums===nums3值一样";
}else
{
echo "nums!==nums3值不一样";
}
//(4)不是同一种数据类型,则为false
echo "
不是同一种类型为false不全等********************************
";
if($nums===true)
{
echo "nums===true";
}else
{
echo "nums!==true";
}
echo "
";
if($person001===true)
{
echo "person001===true";
}else
{
echo "person001!==true";
}
?>
*************************************************************
require_once "Person.php";
header("content-type:text/html;charset=utf-8");
$person001=new Person("wuxifu", 110);
$person002=new Person("wuxifu", 110);
$person003=$person001;
//等(==)判断首先要数据类型一样不,不一样的话,如果等号有一边是boolean类型则另一边转换成boolean类型,否则等号右边的会强制转换成左边的数据类型
//(1)是同一数据类型后,如果是对象(只要两对象的内容一样则为true否者为false)
echo "
person001与person002不是同一对象的情况下,但内容一样等*************
";
if($person001==$person002)
{
echo "person001==person002内容一样";
}else
{
echo "person001!=person002内容不一样";
}
echo "
person001与person003是同一对象的情况下(内容一样),等**************
";
if($person001==$person003)
{
echo "person001==person003是同一对象";
}else
{
echo "person001!=person003不是同一对象";
}
//(2)是同一数据类型后,如果是数组(如果内容一样则为true否者为false)
$array=array(110,120,130);
$array2=array(110,120,130);
$array3=$array;
echo "
array与array2不是同一数组,但内容一样,等*************
";
if($array==$array2)
{
echo "array==array2";
}else
{
echo "array!=array2";
}
echo "
array与array3不是同一数组,但内容一样,等************************
";
if($array==$array3)
{
echo "array==array3";
}else
{
echo "array!=array3";
}
echo "
array与array3不是同一数组,内容也不一样,不等***********************
";
$array3[0]=0;
if($array==$array3)
{
echo "array===array3";
}else
{
echo "array!==array3";
}
echo "
";
//(3)是同一数据类型后,如果是四种标量类型(boolean,integer,float,string),值一样则为true否者为false
echo "
是同一数据类型后,如果是四种标量类型(boolean,integer,float,string),值一样则为true否者为false
";
$nums=110;
$nums2=120;
$nums3=110;
if($nums==$nums2)
{
echo "nums==nums2值一样";
}else
{
echo "nums!==nums2值不一样";
}
echo "
";
if($nums==$nums3)
{
echo "nums==nums3值一样";
}else
{
echo "nums!=nums3值不一样";
}
//(4)不是同一种数据类型,如果等号某一边有boolean类型的值,则将另一边转换成boolean类型,否则等号右边的会转成等号左边的数据类型
echo "
不是同一种数据类型,如果等号某一边有boolean类型的值,则将另一边转换成boolean类型,否则等号右边的会转成等号左边的数据类型********************************
";
if($nums==true)
{
echo "nums==true";
}else
{
echo "nums!=true";
}
echo "
";
if($person001==true)
{
echo "person001==true";
}else
{
echo "person001!=true";
}
echo "
";
if(true==$nums)
{
echo "true==nums";
}else
{
echo "true!=nums";
}
echo "
";
if(true==$person001)
{
echo "true==person001";
}else
{
echo "true!=person001";
}
echo "
";
if($array==$person001)
{
echo "array==person001";
}else
{
echo "array!=person001";
}
echo "
";
if($array==true)
{
echo "array==true";
}else
{
echo "array!=true";
}
?>
上一篇: javascript解三阶幻方(九宫格)_javascript技巧
下一篇: js实现右键菜单功能