Is there any difference between ==
and ===
in PHP? Both seem to work fine for me when i use them in a conditional statement.
Asked
Active
Viewed 4.9k times
16

Machavity
- 30,841
- 27
- 92
- 100

user791180
- 212
- 1
- 2
- 7
2 Answers
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.
-
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