Comparision Between == And === Operator

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.

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.