search
HomeDaily ProgrammingPHP KnowledgeThe difference between equal and equal in php

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 "不相等";
}

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 "不相等";
}

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools