title: php syntax for if statement with multiple conditions ( `||` as well as `&&` )
body: <p>Context: On our website, we calculate whether an item/order meets the criteria for free shipping using an if statement evaluating if a value - 'ff' - is true. Depending on conditions met it sets the shipping appropriately. We now require the need to evaluate if an item is free shipping with the order of <em>_</em>. To top it off, for other purposes such as external feeds, another condition must apply (weight must = 0 or have no value), for fw to be free freight. Here is the code, that I can't figure out why it is NOT working:</p>
  
  <pre><code>if($r['freeFreight'] == 'ff' || ($r['freeFreight'] == 'fw' &amp;&amp; ($r['weight'] == 0 || $r['weight'] == '') ) ) {
      $r['shippingStandard'] = 0;
  }
  </code></pre>
  
  <p>Are the conditions overly segregated in the if statement with the sets of ()? Or, are they just incorrectly placed. For example, should it be:</p>
  
  <pre><code>if(($r['freeFreight'] == 'ff') || ($r['freeFreight'] == 'fw' &amp;&amp; $r['weight'] == 0 || $r['weight'] == '') ) {
      $r['shippingStandard'] = 0;                     
  }
  </code></pre>
  
  <p>The second of the two seems more logical to me because: if ($r['freeFreight'] == 'ff') - then regardless of the following conditions the statement should return true and set the variable to 0. Is my logic correct? Sorry for this newb question...</p>
  
  <p>Thanks for any help you can offer.</p>
  
  <hr>
  
  <p>So I think perhaps, based on the answers so far (thanks everybody that has chimed in to help an amateur) - I think I am going to do a trial with:</p>
  
  <pre><code>if( ($r['freeFreight'] == 'ff') || ( $r['freeFreight'] == 'fw' ) &amp;&amp; empty( $r['weight'] ) ) { 
      $r['shippingStandard'] = 0;
  }
  </code></pre>
  
  <p>Planning to run trial with this, if it is fundamentally wrong, please advise.</p>