Home > Backend Development > PHP Problem > What do the two equal signs mean in php?

What do the two equal signs mean in php?

青灯夜游
Release: 2023-03-11 06:06:02
Original
6845 people have browsed it

In PHP, two equal signs "==" means "equal". It is a comparison operator used to compare whether the expressions or variables on both sides of the equal sign are equal. It only compares values, not types; Returns true if they are equal, false if not.

What do the two equal signs mean in php?

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

In php, two equal signs "= "=" means "equality" and is a comparison operator used to compare whether the expressions or variables on both sides of the equal sign are equal.

Use two equal signs "==" for comparison. Only values ​​are compared, not types.

There is also a triple equal sign "==" in PHP, which means "identity", that is, absolute equality (both values ​​and types are equal); using three equal signs === for comparison, in addition to comparing values, also Compare types.

For example, "42" is a string and 42 is an integer. FALSE is a boolean value and "FALSE" is a string.

<?php
if(42 == "42") {
    echo &#39;1、值相等&#39;;
}
 
echo PHP_EOL; // 换行符
 
if(42 === "42") {
    echo &#39;2、类型相等&#39;;
} else {
    echo &#39;3、类型不相等&#39;;
}
?>
Copy after login

Output:

1、值相等
3、类型不相等
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What do the two equal signs mean in php?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template