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

The difference between = and == in php

Guanhui
Release: 2023-03-01 06:42:01
Original
3788 people have browsed it

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。
?>
Copy after login

Comparison operator

##$a == $b is equal to $a === $bCongruent$a != $bNot equal$a <> $b$a !== $b$a < $b$a > $b$a <= $b$a >= $b$a <=> $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.
小与TRUE, if$a is strictly smaller than $b.
is greater than TRUE if $a is strictly greater than $b.
is less than or equal to TRUE, if $a is less than or equal to $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!

Related labels:
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template