0

In PHP, is

if(!$foo)

equivalent with

if($foo != true)

or with

if($foo !== true)

or is it even something completly different of both?

Foo Bar
  • 1,764
  • 4
  • 24
  • 43
  • 1
    all of them are same! – RNK Dec 05 '14 at 15:52
  • a simple run can give you the right answer. –  Dec 05 '14 at 15:55
  • See also [Reference - What does this symbol mean in PHP?](http://stackoverflow.com/q/3737139) – mario Dec 05 '14 at 16:00
  • possible duplicate of [Reference - What does this symbol mean in PHP?](http://stackoverflow.com/questions/3737139/reference-what-does-this-symbol-mean-in-php) –  Dec 05 '14 at 16:09

4 Answers4

4

Note that,

== OR != compares the values of variables for equality, type casting as necessary. === OR !== checks if the two variables are of the same type AND have the same value.

This answer will give you better explanation of this concept: https://stackoverflow.com/a/80649/3067928

Community
  • 1
  • 1
RNK
  • 5,582
  • 11
  • 65
  • 133
  • I'm not asking about the difference between `==` and `===` (or their negations), which I know. I'm asking about their relation to `!`. – Foo Bar Dec 05 '14 at 16:25
3
if(!$foo)

is the equivalent to

if($foo != true)

so

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

will ouptut "asd"

Alexis Peters
  • 1,583
  • 1
  • 10
  • 17
-1

$a != $b

TRUE if $a is not equal to $b after type juggling.

$a !== $b

TRUE if $a is not equal to $b, or they are not of the same type.


See type juggling in PHP for more info on type juggling.


Sources : php.net

Jay S.
  • 1,318
  • 11
  • 29
  • I'm not asking about the difference between `==` and `===` (or their negations), which I know. I'm asking about their relation to `!`. – Foo Bar Dec 05 '14 at 16:27
-1

Its not the same

!= is No equal (Returns true if  is not equal)
!== is Not identical  (Returns true if  is not equal , or they are not of the same type)
Jelle Keizer
  • 723
  • 5
  • 9
  • I'm not asking about the difference between `==` and `===` (or their negations), which I know. I'm asking about their relation to `!`. – Foo Bar Dec 05 '14 at 16:28