Created
May 19, 2022 02:52
-
-
Save terashim/0fa143a3f11f6ce6895739a06993eb19 to your computer and use it in GitHub Desktop.
[PHP] 配列とオブジェクトのそれぞれに対して比較演算子 `==` と一致演算子 `===` の挙動を確認する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* 配列とオブジェクトのそれぞれに対して | |
* 比較演算子 `==` と一致演算子 `===` の挙動を確認する | |
*/ | |
// 配列 | |
$a = ["value" => 1]; | |
$b = ["value" => 1]; | |
var_dump($a == $b); // 比較演算子 | |
# ==> bool(true) | |
var_dump($a === $b); // 一致演算子 | |
# ==> bool(true) | |
// オブジェクト | |
$a = new stdClass(); | |
$a->value = 1; | |
$b = new stdClass(); | |
$b->value = 1; | |
var_dump($a == $b); // 比較演算子 | |
# ==> bool(true) | |
var_dump($a === $b); // 一致演算子 | |
# ==> bool(false) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment