Home >Backend Development >PHP Problem >The difference between = and == in php

The difference between = and == in php

Guanhui
GuanhuiOriginal
2020-05-09 13:55:323759browse

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

##$a == $b is equal to $a === $bCongruent$a != $bNot equal$a a8093152e673feb7aba1828c43532094 $b$a !== $b$a 110a5e5e3ad431a99af5e0bd8b042dbd $b$a e570929f58c282256da5b7095a3f0a98= $b$a 96b4fef55684b9312718d5de63fb7121 $b Recommended tutorial: "
Example Name Result
TRUE, if $a is equal to $b after type conversion.
TRUE, if $a is equal to $b, and they are also of the same type.
##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.
PHP Tutorial

"

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn