关系运算符===(用于相同)可以与!=运算符交替使用“并获得相同的结果吗?或者当我执行更大的程序时,最终会遇到问题吗?can ===和!=可互换使用吗?
我知道我会在下面的例子同样的结果,这将始终是真的吗?
//example 1
<?php
$a = 1; //integer
$b = '1'; //string
if ($a === $b) {
echo 'Values and types are same';
}
else {
echo 'Values and types are not same';
}
?>
// example 2
<?php
$a = 1; //integer
$b = '1'; //string
if ($a != $b) {
echo 'Values and types are not same';
}
else {
echo 'Values and types are same';
}
?>
你为什么要这样做? PHP的运营商已经够混乱了。 – BoltClock
!=不相等,你需要!==不等于不相同的类型。 http://php.net/manual/en/language.operators.comparison.php – ace
检查这个问题,你不会喜欢使用'=='或'!=',http://stackoverflow.com/questions/ 12598407/php -expressings-two-different-strings-to-the-the-same – xdazz