Re: Difference between & &&

From: Date: Sat, 08 Mar 2003 05:23:28 +0000
Subject: Re: Difference between & &&
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-138723@lists.php.net to get a copy of this message
On March 7, 2003 08:54 pm, James Taylor wrote: > Ok, this may have already been posted to the list already, but the > archives don't seem to like the & and && characters. > > I'm running into some code that looks like this: > > <snip> > Define('INPUT', 2); > <snip> > if($search->level & INPUT) $tmp.= $search->input(); > > > Ok, what's the & mean? > > As far as I could tell from the very little documentation I was > able to scrape up on google, & is a bit-by-bit operator. Thus, if > either INPUT or $search->level, we get TRUE... If that's the case, > what's the point of using it instead of || ? > > Or, do I just totally not understand the point of this. Thanks Ok shoot me if I'm wrong here I just vaguely recall this from some Java course I took. I think && and & are identical except that if you use &, PHP will not short circuit the expression. like: $x = 0; if(false && $x++) print "impossible"; print $x; // should print 0 $x = 0; if(false & $x++) print "impossible"; print $x; // should print 1 Warning: This may only work for Java or maybe I just can't remember it properly.. leo

« previous php.general (#138723) next »