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

What do the two equal signs mean in php?

青灯夜游
青灯夜游Original
2021-06-29 18:58:566793browse

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;;
}
?>

Output:

1、值相等
3、类型不相等

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!

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