equals =,==,===

Since PHP does have type safe aspects to the language, for example within in c++ if you declared a variable to be of type int(eger) and other to be string and then to see if they was the same value, the compiler would complain because they are of different types so you need to convert one or the other to the same type before doing the check. Well in PHP if you had the a variable with the same value as such.

$intvalue = (int)4;
$strint = "4";

and did a test to see if they was the same in value then

if ($intvalue == $strint)
	echo "they are the same!, but one is a string and the other is a integer!";

would work since php does converts them into the same types to then do a comparison, but if you wanted to make sure that they are of the same types then use the ===

if ($intvalue=== $strint)
   echo "this should not show!!!.. because there types are different!!";
else
   echo "they may have same 'value', but they are different types so not equal";

the 3 equals (===) means compare the values and also the types, which in turn the else part of the if condition would be printed because, yes they are the “same” value but of different types and thus they are not equal.

Leave a Reply

Your email address will not be published. Required fields are marked *