Geo*_*Geo 1 php arrays comparison object
$a = new stdClass;
$a->first = 'James';
$a->last = 'Doe';
$b = (object) [
'first' => 'James',
'last' => 'Doe',
];
echo 'Loose compare: ' . ($a == $b ? 'equal' : 'different') . PHP_EOL; // equal
echo 'Type compare: ' . (gettype($a) == gettype($b) ? 'equal' : 'different') . PHP_EOL; // equal
echo 'Strict compare: ' . ($a === $b ? 'equal' : 'different') . PHP_EOL; // different
Run Code Online (Sandbox Code Playgroud)
怎么严格比较不好?更重要的是,它们可以严格相同吗?
严格比较,如果检查$a和$b是完全相同的对象(相同的存储器位置).使它们相同(严格)的唯一方法是 $a = $b;
请参阅http://php.net/manual/en/language.oop5.object-comparison.php以供参考