Comparision Between == And === Operator
== - Weak Type Operator
For Example:
$test = 0;
if($test == “My Comparision”){
echo “hi”;
}else{
echo “bye”;
}
It will print hi instead of bye.Becaues before comparing $test and the string, automatically php will do the type casting. Php will compare like this
if((int)$test == (int)(”My Comparision”)){
echo “hi”;
}else{
echo “bye”;
}
(int)(”My Comparision”) will give 0.So it will print hi.
=== - It will chcek both the value and type.
So if you use
if($test === “My Comparision”){
echo “hi”;
}else{
echo “bye”;
}
It will print bye. But before using === operator, be aware both values you comparing are from same type.
