If and If.?

Discussion in 'PHP' started by masterofzoo, Nov 5, 2011.

  1. #1
    Hi, everyone I have a question about PHP code,
    I want to write a code so that many conditions must be accepted before proceeding to the next step:-

    for example:-

    if jean go to school and he did homework and his grade was A and his attendance complete..........give him a sandwich:eek::eek:,

    how can I make this in PHP, I am familiar with the rule of IF but Idon't know how to make many conditions "not only one" to be verified before going to the next step and do the order
     
    masterofzoo, Nov 5, 2011 IP
  2. Blink UI ™

    Blink UI ™ Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    if ( value1 = condition1 && value2 = condition2 && value3 = condition3) {
    
        // All of the above are true
    
    } else {
    
        // Not all conditions were met
    
    }
    PHP:
    The same for OR - you just need to replace && with ||.
     
    Blink UI ™, Nov 5, 2011 IP
  3. absentx

    absentx Peon

    Messages:
    98
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes, exactly what blink says.

    
    // under the assumption you are setting all these variables to true or false earlier in your script
    if ($jean_school && $jean_homework && $jean_grade && $jean_attendence_awesome){
     $jean_sandwich = true;
    }
    else
     $jean_is_a_loser = true;
    }
    
    PHP:
     
    absentx, Nov 5, 2011 IP
  4. rainborick

    rainborick Well-Known Member

    Messages:
    424
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    120
    #4
    Blink's got it, but I'd nitpick a bit about the syntax for clarity:
    
    if ( (value1 == condition1) && (value2 == condition2) && (value3 == condition3) ) {
    
        // All of the above are true
    
    } else {
    
        // Not all conditions were met
    
    }
    
    PHP:
     
    rainborick, Nov 5, 2011 IP
  5. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #5
    Then you aren't familiar with the IF statement...at all. Goto the PHP website they explain this in detail
     
    NetStar, Nov 29, 2011 IP