php等號(==)與全等(===)

<?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”;

}

?>

*************************************************************

<?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;
//等(==)判斷首先要數據類型一樣不,不一樣的話,如果等號有一邊是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”;

}

?>

發佈留言