|| && ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chunk1978
    New Member
    • Jan 2007
    • 224

    || && ?

    it is proper syntax to use "||" and/or "&&" within PHP IF/ELSE statements like javascript?
  • chunk1978
    New Member
    • Jan 2007
    • 224

    #2
    here's an example of what i mean:

    Code:
    if	(($specifycountry != "Country0") || ($specifycountry != "Country44"))
    	{echo "$specifycountry<br>\n";}
    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?

    Comment

    • tolkienarda
      Contributor
      • Dec 2006
      • 316

      #3
      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

      Comment

      • code green
        Recognized Expert Top Contributor
        • Mar 2007
        • 1726

        #4
        [PHP]if (($specifycount ry != "Country0") || ($specifycountr y != "Country44" ))
        {echo "$specifycountr y<br>\n";} [/PHP]

        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.

        Comment

        Working...