Re: ! and !=

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux