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

The difference between equal and equal in php

Jan 15, 2019 pm 02:40 PM

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!

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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)