AND within IF statement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • geraldjr30
    New Member
    • Jan 2009
    • 60

    AND within IF statement

    hi,

    i have the following:

    Code:
    if(!isset($_POST['submit'])  AND ($_POST['fac'] ="ALL")))
    but i think the syntax is wrong. could someone help?

    thanks in advance,
    geebee
  • hoopy
    New Member
    • Feb 2009
    • 88

    #2
    I always use && and syntax as follows:

    Code:
    function aFunction($a)
    {
      return false;
    }
    
    function bFunction($b)
    {
      return true;
    }
    
    if( !aFunction($a) && bFunction($b) )
    {
      echo("Condition met.");
    } else {
      echo("Condition failed.");
    }
    So i guess in your case it would be something like:

    Code:
    if( !isset($_POST['submit']) && $_POST['fac'] == "ALL" )
    You were using = instead of ==

    Cheers

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      Remember '=' is an assignment operator and '==' is a comparison operator.

      Also '===' is a comparison operator which checks for the type of the variable, too.

      Comment

      • nathj
        Recognized Expert Contributor
        • May 2007
        • 937

        #4
        Originally posted by geraldjr30
        hi,

        i have the following:

        Code:
        if(!isset($_POST['submit'])  AND ($_POST['fac'] ="ALL")))
        but i think the syntax is wrong. could someone help?

        thanks in advance,
        geebee
        You simply have one too many closing brackets.

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          Even tho this doesn't matter in this case, it is worth noting that even tho the AND and && operators seem work the same, && has a higher precedence, so exchanging them may actually change the result of an expression.
          (See PHP: Operator Precedence)

          For example:
          [code=php]
          $var = true && false; // $var == false
          $var = true and false; // $var == true[/code]

          Comment

          Working...