Home >Backend Development >PHP Problem >The difference between = and == in php
The difference between = and == in php
The former means assignment, and its function is to assign the data on the right to the left Variable, the latter means to compare whether the value on the left and the value on the right are equal. If they are equal, the result is TRUE, otherwise it is FALSE.
Assignment operator
The basic assignment operator is "=". At first you may think it is "equal to", but it is not. It actually means assigning the value of the expression on the right to the operand on the left.
The value of the assignment operation expression is the assigned value. That is, the value of "$a = 3" is 3. This way you can do some tricks:
<?php $a = ($b = 4) + 5; // $a 现在成了 9,而 $b 成了 4。 ?>
Comparison operator
Example | Name | Result |
---|---|---|
is equal to |
TRUE , if $a is equal to $b after type conversion.
|
|
Congruent |
TRUE , if $a is equal to $b, and they are also of the same type.
|
|
Not equal | ##TRUE, if after type conversion $a is not equal to $b.
|
|
Not equal | TRUE, if type conversion After $a is not equal to $b.
|
|
Not Congruent | TRUE, if $a is not equal to $b, or they are of different types.
|
|
is greater than | TRUE if $a is strictly greater than $b.
|
|
is greater than or equal to | TRUE, if $a is greater than or equal to $b.
|
|
Combined with comparison operators | when | $a Less than, equal to, or greater than than$b Returns a integer value that is less than, equal to, or greater than 0 respectively. PHP7 is now available. |
The above is the detailed content of The difference between = and == in php. For more information, please follow other related articles on the PHP Chinese website!