Re: ! and !=

From: Date: Wed, 22 Apr 2009 22:51:46 +0000
Subject: Re: ! and !=
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-291840@lists.php.net to get a copy of this message
George Langley wrote:
Hi all. Maybe I'm just getting confused by all the languages I'm trying to work with! But, isn't: if(!$var1 == $var2){ the same thing as if($var1 != $var2){ #1 doesn't work, #2 does. Thanks!
No. The second is seeing if $var1 is not equal to $var2. The first one is doing a "not $var1" is equal to $var2 - which will change it from whatever it is into false. (It's currently set - so that's true, you're switching that - so it becomes false). $ cat test.php <?php $a = 5; var_dump($a); $b = !$a; var_dump($b); $ php test.php int(5) bool(false) So the "not $var1" becomes false. -- Postgresql & php tutorials http://www.designmagick.com/

« previous php.general (#291840) next »