Home >Backend Development >PHP Tutorial >Detailed explanation of the use of === in php_php example

Detailed explanation of the use of === in php_php example

WBOY
WBOYOriginal
2016-12-05 13:28:152312browse

When comparing simple types (such as String int float bool), the judgment is "equal && same type"

$num1 = 123;
$num2 = 123;
$num3 = '123';
var_dump($num1 === $num2);//输出 bool(true)
var_dump($num3 === $num1);//输出 bool(false) 因为$num3是字符串 $num1是整型

When comparing objects, what is judged is "whether they point to the same object"

class Person {
public $name;
}
$p1 = new Person();
$p1->name = 123;
$p2 = new Person();
$p2->name = 123;
var_dump($p1 === $p2);//输出 bool(false),这是俩对象,虽然都是Person类型且值相等
var_dump($p1 == $p2); //输出 bool(true),俩对象的值是一样的。

The above is the use of === in php introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for your support of the Script House 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