What is the difference between identity and equal in php

青灯夜游
Release: 2023-03-15 10:46:02
Original
3579 people have browsed it

Difference: 1. Identity uses the "===" operator for calculation, while equality uses the "==" operator for calculation; 2. The equality operation only tests whether the variable on the left has the same value as the variable on the right. values, while the identity operation tests not only whether the values ​​are the same, but also whether the data types are the same.

What is the difference between identity and equal in php

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

php Comparison of identity and equality

Equality (==) operation

Equality (==) operator is comparison, union Tests whether the variable (expression or constant) on the left has the same value as the variable (expression or constant) on the right; the comparison performed by this operator is loose.

If the two values ​​​​are the same (it only compares the value of the variable, not the data type), it returns a true value; if the two values ​​​​are not the same, it returns a false value.

Note: The equality (==) operator and the assignment (=) operator are different. The assignment (=) operator changes the variable on the left, assigning the variable on the right to the variable on the left, while the equality (==) operator tests for equality and returns true or false depending on the comparison.

Example:

<?php 
header("content-type:text/html;charset=utf-8");  
// 给变量赋整数值
$x = 999; 
echo &#39;$x=&#39;.$x."<br>"; 
// 给变量赋字符串值
$y = &#39;999&#39;; 
echo &#39;$y=&#39;.$y."<br>"; 
//比较$x 和$y 
if ($x == $y) 
    echo &#39;$x和$y的值相等&#39;; 
else
    echo &#39;$x和$y的值不相等&#39;; 
?>
Copy after login

What is the difference between identity and equal in php

Identity (===) operation

Identity (===) operation operator performs a strict comparison between given variables or values; it compares and sees if two variables (expressions or constants) are equal in value and have the same data type, i.e. both are strings or both are Integers and so on.

This operator returns true if two variables (expressions or constants) contain the same value and the same data type, otherwise it returns false.

Example:

<?php 
header("content-type:text/html;charset=utf-8");  
// 给变量赋整数值
$x = 999; 
echo &#39;$x=&#39;.$x."<br>"; 
// 给变量赋字符串值
$y = &#39;999&#39;; 
echo &#39;$y=&#39;.$y."<br>"; 
//比较$x 和$y 
if ($x === $y) 
    echo &#39;$x和$y相等&#39;; 
else
    echo &#39;$x和$y不相等&#39;; 
?>
Copy after login

What is the difference between identity and equal in php

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What is the difference between identity and equal 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