16

Possible Duplicate:
The 3 different equals

Is there any difference between == and === in php? both seem to work fine for me when i use them in a conditional statement. I am very new to programming in PHP. Please consider this and answer in simple words.

Community
  • 1
  • 1
user791180
  • 212
  • 1
  • 2
  • 7
  • You are not the first person to ask this question. http://stackoverflow.com/questions/80646/ http://stackoverflow.com/questions/4732706/ http://stackoverflow.com/questions/3641819/ http://stackoverflow.com/questions/589549/ http://stackoverflow.com/questions/3053420/ – Matt Ball Jun 11 '11 at 15:37
  • Sorry. I didnt know it. Next time i will surely check for other questions on this site. thanks. – user791180 Jun 11 '11 at 15:39
  • And why not check the PHP manual whilst you're at it? – Lightness Races in Orbit Jun 11 '11 at 16:13
  • duplication question http://stackoverflow.com/questions/2063480/the-3-different-equals –  Aug 14 '15 at 09:37

2 Answers2

22
  • $a == $b

Equal true: if $a is equal to $b, after type juggling.


  • $a === $b

Identical true: if $a is equal to $b, and they are of the same type.

nbro
  • 13,796
  • 25
  • 99
  • 185
evilone
  • 21,970
  • 7
  • 78
  • 106
  • what is your mean of *same type* ? iIf `$a == $b` be true, then certainly they are of the same type. is it not ? can you give me a example that they be `==` (true) but `===` (false) ? – Shafizadeh Aug 11 '15 at 13:18
  • @Sajad here http://www.php.net/manua/en/language.operators.comparison.php is a lot of examples – evilone Aug 11 '15 at 13:36
  • @Shafizadeh http://www.7codes.info/post/4/difference-between-==-and-=== in example "22" is string and 22 is integer. They are not the same type because one is string, another integer. With `==` they are equal, but with `===` are not equal – user2360831 May 24 '19 at 06:16
8

Identical:

$a === $b

TRUE if $a is equal to $b, and they are of the same type. (introduced in PHP 4)

Equal:

$a == $b

TRUE if $a is equal to $b after type juggling.

Read here for more: http://www.php.net/manual/en/language.operators.comparison.php

Drenmi
  • 8,267
  • 4
  • 40
  • 51
check123
  • 1,979
  • 2
  • 22
  • 28