1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

if (something.. && (something || something)) plz help

Discussion in 'PHP' started by arpit13, Nov 20, 2010.

  1. #1
    hello.

    i was think if i can use if like this:
    
    if (condition1 && (condition2 || condition3))
    //or this will be fine:
    if (condition1 && condition2 || condition3)
    
    PHP:

     
    arpit13, Nov 20, 2010 IP
  2. shofstetter

    shofstetter Well-Known Member

    Messages:
    178
    Likes Received:
    7
    Best Answers:
    1
    Trophy Points:
    120
    #2
    no they will evaluate differently.
    if cond1 and result of cond2 or cond3
    if cond1 and cond2 or cond3
     
    shofstetter, Nov 20, 2010 IP
  3. CPAPubMichael

    CPAPubMichael Peon

    Messages:
    231
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i think this is what you mean.

    
     if($con1 || $con2 || $con3){
      
       //your data here
    
     }
    
    PHP:
    if that is not what you mean then please do let me know.
     
    CPAPubMichael, Nov 20, 2010 IP
  4. helloguys12345678

    helloguys12345678 Greenhorn

    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    20
    #4
    Acutally that won't work.

    His condition is cond1 AND EITHER cond2 or cond3
    meaning COND1 MUST be true AND EITHER cond2 or cond3 must be true

    In your version, even if cond1 is false, the condition will still pass, which is not how it's supposed to work.
     
    helloguys12345678, Nov 20, 2010 IP
  5. arpit13

    arpit13 Well-Known Member

    Messages:
    294
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    128
    Digital Goods:
    1
    #5
    i actually wanted to do so.i just want that cond1 must be true and one the cond2 or cond3 must be true.
    so
     if (condition1 && (condition2 || condition3)) 
    Code (markup):
    is correct?
     
    arpit13, Nov 20, 2010 IP
  6. shofstetter

    shofstetter Well-Known Member

    Messages:
    178
    Likes Received:
    7
    Best Answers:
    1
    Trophy Points:
    120
    #6
    that is correct.

    here is the long evaluation of your statement
    if (condition1 is true and (condition2 is true or condition3 is true)
    so as long as either condition2 or condition3 is true and condition1 is true the if statement will execute;
     
    shofstetter, Nov 20, 2010 IP
    arpit13 likes this.
  7. arpit13

    arpit13 Well-Known Member

    Messages:
    294
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    128
    Digital Goods:
    1
    #7
    ok thanks for the reply.
     
    arpit13, Nov 21, 2010 IP
  8. w47w47

    w47w47 Peon

    Messages:
    255
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    why don't you just test such things on localhost? just to be sure.
     
    w47w47, Nov 22, 2010 IP
  9. arpit13

    arpit13 Well-Known Member

    Messages:
    294
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    128
    Digital Goods:
    1
    #9
    i was in b/w developing a script and i was not getting wat i wanted but i was unable to find error.
    so i asked here if that if command is a problem.
     
    arpit13, Nov 23, 2010 IP