>  기사  >  백엔드 개발  >  php等号(==)与全等(===)_PHP教程

php等号(==)与全等(===)_PHP教程

WBOY
WBOY원래의
2016-07-13 10:22:27883검색

php等号(==)与全等(===)

\

require_once "Person.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";

}

?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/847855.htmlTechArticlephp等号(==)与全等(===) require_once "Person.php'; header("content-type:text/html;charset=utf-8"); $person001=new Person("wuxifu", 110); $person002=new Person("wuxifu", 110); $...
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.