The 3 different equals

What is the difference between = , == , and === ?

I think using one equal sign is to declare a variable while two equal signs is for a comparison condition and lastly three equal signs is for comparing values of declared variables.


You have = the assignment operator , == the 'equal' comparison operator and === the 'identical' comparison operator .

$a = $b     Assign      Sets $a to be equal to $b.
$a == $b    Equal       TRUE if $a is equal to $b.
$a === $b   Identical   TRUE if $a is equal to $b, and they are of the same type. (introduced in PHP 4)

For more info on the need for == and === , and situations to use each, look at the docs.


  • = is the assignment operator
  • == is the comparison operator (checks if two variables have equal values)
  • === is the identical comparison operator (checks if two variables have equal values and are of the same type).

  • = assignment operator

    == checks if two variables have the same value

    === checks if two variables have the same value AND if their types are the same

    链接地址: http://www.djcxy.com/p/1792.html

    上一篇: PHP!=和==运算符

    下一篇: 3个不同的等于