php中的if(true)/else(false)和if(!true)之间有什么区别


What is the difference between an if (true)/else (false) and a if(!true) in php?

if (${"old_tag_$x"} == $tag) {
} else {
    ${"old_tag_$x"} = $tag;
    setTermFieldbyId('tag', $tag, $x);
}

这很好用。然而,它看起来确实很冗长,所以我试着这样简化它:

if (!${"old_tag_$x"} == $tag) {
    ${"old_tag_$x"} = $tag;
    setTermFieldbyId('tag', $tag, $x);
}

然而,这根本不起作用。还在想办法,但这对我来说似乎不合乎逻辑。我错了吗?

应该是

if (${"old_tag_$x"} != $tag) {
     ${"old_tag_$x"} = $tag;
     setTermFieldbyId('tag', $tag, $x);
}

http://www.php.net/manual/en/language.operators.comparison.php

来自手册:

$a!=$b如果类型杂耍后$a不等于$b,则不等于TRUE。

还要注意,=====(或!=!==(是不同的。=====宽松。===需要变量类型匹配(例如字符串等于字符串,或者整数等于整数(。

例如:

1==='1'

是真的,但是

1==='1'

是错误的

这里还有一个关于这方面的文档链接,http://php.net/manual/en/types.comparisons.php.这是一个功能演示,http://sandbox.onlinephpfunctions.com/code/70adc739a1062ee91944b7bf75574643946ecc17