The equal and equal operators in PHP are == and === respectively. They are comparison operators. Comparison operators allow you to compare two values. So what are the specific differences between the two operators equal (==) and full equal (also called absolute equal (===)) in PHP?
Below we will introduce to you the difference between == and === with a simple code example.
1. When we use the == symbol for comparison
The code example is as follows:
<?php $a=true ; $b=8; $c='8'; if($a=='true'){ echo "相等"; }else{ echo "不相等"; } echo '<br>'; if($b==$c){ echo "相等"; }else{ echo "不相等"; }
At this time, the judgment output is as follows:
2. When we use the === symbol to compare
The code example is as follows:
<?php $a=true ; $b=8; $c='8'; if($a==="true"){ echo "相等"; }else{ echo "不相等"; } echo '<br>'; if($b===$c){ echo "相等"; }else{ echo "不相等"; }
The judgment output at this time is as follows:
In the example, the variable $a is a Boolean type , and $b is an integer type , $c is a string, and "true" represents the string .
Difference:
== operator means that if $b is equal to $c, it returns true. (Equal values) The
=== operator means that if $b is equal to $c, and they have the same type, then return true. (Equal values and equal types)
As in the above example:
true=="true", if their values are equal, true will be returned;
true===" true", if their values are equal but their types are different, false is returned.
Similarly:
8==‘8’ returns true;
8===‘8’ returns false.
Note: In PHP, the basic assignment operator is "=". It means that the left operand is set to the value of the right-hand expression.
This article is about the specific differences between equal == and all equal === in PHP. I hope it will be helpful to friends in need!
The above is the detailed content of The difference between equal and equal in php. For more information, please follow other related articles on the PHP Chinese website!