RE: [PHP] Help with Logical 'OR'

From: Date: Tue, 29 Jan 2002 03:25:27 +0000
Subject: RE: [PHP] Help with Logical 'OR'
Groups: php.general 
Request: Send a blank email to php-general+get-82510@lists.php.net to get a copy of this message
basically it's to do with "lazy evaluation" or whatever it's called.... * logical expressions are read from left to right. * with OR, the expression reading is halted when the first TRUE is found * with AND, the expression reading is halted when the first FALSE is found so with : if (true||false) php will stop processing when it comes across the "true" and with : if (false&&true) php will stop processing when is comes across the "false" in both cases, this means that whatever the second expression is, it wont get "executed" hope that explains it a bit furthur Martin -----Original Message----- From: jv [mailto:jveillo@bellsouth.net] Sent: Tuesday, January 29, 2002 2:26 PM To: php-general@lists.php.net Subject: Re: [PHP] Help with Logical 'OR' Thanks Matt, Jeff, and Sam (BTW Sam, for some reason your post didn't come to me on the list through regular email- I found it when I did a search in the archives at php.net. I 'm pretty sureI didn't delete it. I mention this because I'm sure the list server hiccups sometimes and I'd hate to offend someone by not thanking or acknowledging them :-) Also, the truth tables are helpfull in visualizing the different logical conditions- thanks!) Anyway, I've tried all combinations yet still can't get (true||fale) or (true&&false) to work, even by using (!empty) or (!isset). I recall reading something about that if a cetrtain envioronmental variable isn't set to 'on' on the server then... I'm not sure what I'm talking about so I'll try to look it up again. I know that I could just nest functions but I'm trying to learn alternatives... > At 02:04 PM 1/28/2002 -0600, jv wrote: > >It seems that only the first condition is being evaluated. > > > >I know that if both of the following conditions are false then the second > >set of statements should get read, and that's what happens, but when I set > >$name to true and $text to false (true||false) then the first set gets read. > > > >Shouldn't both conditions be true in order for the first set of statements > >be read? Why would the first set of statements get read when the conditions > >are (true||false)? > > > >Thanks in advance for your help. > >james > > > >******************************************************************** > >if ($name || $text) > > > > { > > > > $text = stripslashes("$text"); > > print "Hello $name\n<br>"; > > print "You said:\n<br> $text\n"; > > > > }else{ > > > > print "Sorry, but you seem to have left one or more entries blank.<br>\n"; > > print "Please return to <a > > href=\"/prac/form.html\">form</a>\n"; > > print " and complete the input<br>\n"; > > > >} > >********************************************************************** > > > > -- > 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 > -- 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

« previous php.general (#82510) next »