Home > Daily Programming > PHP Knowledge > The difference between equal and equal in php

The difference between equal and equal in php

藏色散人
Release: 2019-01-17 09:07:00
Original
9713 people have browsed it

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?

The difference between equal and 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=&#39;8&#39;;

if($a==&#39;true&#39;){
    echo "相等";
}else{
    echo "不相等";
}
echo &#39;<br>&#39;;
if($b==$c){
    echo "相等";
}else{
    echo "不相等";
}
Copy after login

At this time, the judgment output is as follows:

The difference between equal and equal in php

2. When we use the === symbol to compare

The code example is as follows:

<?php
$a=true ;
$b=8;
$c=&#39;8&#39;;

if($a==="true"){
    echo "相等";
}else{
    echo "不相等";
}
echo &#39;<br>&#39;;
if($b===$c){
    echo "相等";
}else{
    echo "不相等";
}
Copy after login

The judgment output at this time is as follows:

The difference between equal and equal in php

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!

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