php全等()
程序员文章站
2022-04-16 14:32:09
...
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";
}
?>
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";
}
?>
上一篇: Python中流程控制语句的详细介绍
下一篇: net4.0怎么安装