Re: assignment operator works for comparison??

From: Date: Wed, 11 Apr 2001 08:38:45 +0000
Subject: Re: assignment operator works for comparison??
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-48125@lists.php.net to get a copy of this message
Hi, Dan wrote: > > > if($shiny = 0){ > > This does not compare anyting, it assigns 0 to $shiny > > yes i know, but shouldnt this operation return true? No, it doesn't return true. The "=" operator returns the value of the expression on its right hand side. Therefore, the statement given above is equivalent to (as far as the if is concerned): if (0) { because the "=" operator returns 0, the value on its right hand side. That is why a statement like: a = b = c = 2 sets all the above variables to 2. Otherwise, if it were to operate the way you think it should, it would set "c" to 2 and "a" and "b" to "true" ;-). Hope that clears up things for you. -- Regards, Harshdeep Singh Jawanda.

« previous php.general (#48125) next »