Re: assignment operator works for comparison??

From: Date: Wed, 11 Apr 2001 10:41:31 +0000
Subject: Re: assignment operator works for comparison??
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-48139@lists.php.net to get a copy of this message
Dan wrote: > > This confused me for awhile, because the single equal sign seemed to work > for comparison, but created inexplicable errors in my programs. It seems > strange to me that a successful variable value assignment does not return > true. > > example: > > <? > > $shiny = 1; > if($shiny = 0){ echo("This wont print"); } > echo( $shiny ); //this will return 0 > > ?> > > --Dan > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net Okay... First: Checking if $shiny equals 0: if ($shiny == 0) { But that's already been discussed. If you _realy_ want to check if the assignment succeeded: if (($shiny = 0) == 0) { Try the following example: ----- $a = "Hello"; $b = "Wold"; if ($b == $a) print "Yes, b equals a<BR>\n"; else print "No, b doesn't equal a<BR>\n"; if (($b = $a) == $a) print "Yes... now b equals a<BR>\n"; else print "Oops... b still doesn't equal a!<BR>\n"; ----- Output will be: No, b doesn't equal a Yes... now b equals a -- * R&zE: *************************** ** Renze Munnik ** ** E: renze@datalink.nl ** M: +31 6 218 111 43 ***************************

« previous php.general (#48139) next »