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

By | June 4, 2021

All of the above are called operators. Operator is a string which instructs PHP to perform given action.

= is called assignment operator. It is used for assign value to a variable. It will assign value left to the variable.

$x = 5; //5 is assigned to variable x.
$name = "Test string"; // Test string assigned to variable name.

== is called comparison operator. Double equal (==) is used to compare operands on both sides (left and right side). Double equal will ignore the type of operands.

$x = 5;
$y = "5"
$x==$y; //It will give true

=== is also called comparison operator, But it will check the type of the variable along with value.

$x = 5;
$y = "5";
$x === $y; //It will give false. Because types of $x and $y are not same.

I hope it clears. If you need any help add in the comment.

2 thoughts on “What is the difference between = , == and === ?

Leave a Reply