Forum Moderators: coopster

Message Too Old, No Replies

PHP = operator Help

         

andrewsmd

4:20 pm on Dec 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am programming in PHP and I am just curious. I know that sometimes I have to use == and other times I have to use === I just don't know why exactly. I know it has something to do with types but I don't really understand. Does anyone have a good example of simple ifs explaining this. Or, does someone have a good link that explains this. I can't really find anything that has a thorough enough explanation for me. Thanks,

Anyango

4:49 pm on Dec 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



== Returns true if both values are Same.
=== Returns true if both values are same AND they have same data type. check this example

<?
$a=1;
$b="1";
$c=1;

if($a===$b)
{
echo "This will not be printed because although a and b are same but a is integer and b is string";
}

if($a==$b)
{
echo "This will be printed";
}

if($a===$c)
{
echo "<br> This will also be printed, because both a and c are same AND they have same data type";
}

?>

[edited by: Anyango at 4:51 pm (utc) on Dec. 5, 2008]

andrewsmd

5:03 pm on Dec 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks.