Search code examples
phpbooleanoperatorsoperator-precedencenegation

Does PHP negation check with `!` coprrespond to `!=` or to `!==`?


In PHP, is

if(!$foo)

equivalent with

if($foo != true)

or with

if($foo !== true)

or is it even something completly different of both?


Solution

  • if(!$foo)
    

    is the equivalent to

    if($foo != true)
    

    so

    $foo = null;
    if(!$foo){
     echo "asd";
    }
    

    will ouptut "asd"