Connecting Tech Pros Worldwide Forums | Help | Site Map

|| && ?

chunk1978's Avatar
Familiar Sight
 
Join Date: Jan 2007
Posts: 226
#1: Apr 11 '07
it is proper syntax to use "||" and/or "&&" within PHP IF/ELSE statements like javascript?

chunk1978's Avatar
Familiar Sight
 
Join Date: Jan 2007
Posts: 226
#2: Apr 11 '07

re: || && ?


here's an example of what i mean:

Expand|Select|Wrap|Line Numbers
  1. if    (($specifycountry != "Country0") || ($specifycountry != "Country44"))
  2.     {echo "$specifycountry<br>\n";}
  3.  
i'm asking this question because this statement doesn't seem to work because if "Country0" is selected, it will still echo the statement...

any ideas?
tolkienarda's Avatar
Needs Regular Fix
 
Join Date: Dec 2006
Posts: 316
#3: Apr 11 '07

re: || && ?


i took a php class a while back and all of that stuff was in our text books so i would and it is also in several tutorials i have read so i would assume that it is good programing practice. i've always thought the fewer if/else statements the better. i hate lots of code. if i can reduce lines i do

eric
code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,083
#4: Apr 12 '07

re: || && ?


[PHP]if (($specifycountry != "Country0") || ($specifycountry != "Country44"))
{echo "$specifycountry<br>\n";} [/PHP]

Quote:
i'm asking this question because this statement doesn't seem to work because if "Country0" is selected, it will still echo the statement...
Yes, and that is correct. The statement will print if either $specifycountry is not Country0 OR $specifycountry is not Country44. If you select Country0 it will fail the first condition but pass the second and so return TRUE. You need to study your BOOLEAN logic a little more.
Reply