title: PHP excluding specific variable values from foreach statement
body: <p>I am trying to exclude fields from a form from being required. Currently the entire array payment runs through this for each statement. I am trying to keep the fields extra, extra2 and extra3 from being required. The can be set to null or defined as whatever string if empty. This is what I have currently:  </p>
  
  <pre><code>  foreach($p as $key =&gt; $value) {
      $value = trim($value);
      if($value == '') {
        $keyName = preg_replace('/([A-Z])/', " $1", $key);
        $this-&gt;_errors['Payment ' . $keyName] = __('Payment ','cart66') . $keyName . __(' required','cart66');
        $this-&gt;_jqErrors[] = "payment-$key";
      }
  </code></pre>
  
  <p>This is what I have tried, but to no avail:</p>
  
  <pre><code> foreach($p as $key =&gt; $value) {
      $value = trim($value);
      if($value == '' &amp;&amp; $p != 'extra' || 'extra2' || 'extra3') {
        $keyName = preg_replace('/([A-Z])/', " $1", $key);
        $this-&gt;_errors['Payment ' . $keyName] = __('Payment ','cart66') . $keyName . __(' required','cart66');
        $this-&gt;_jqErrors[] = "payment-$key";
      }
  else if ($p['extra'] == '') {
   $_p['extra'] = NULL; 
  }
  else if ($p['extra2'] == '') {
   $_p['extra2'] = NULL; 
  }
  else if ($p['extra3'] == '') {
   $_p['extra3'] = NULL; 
  }
  </code></pre>
  
  <p>}</p>
  
  <p>It's my syntax isn't it? The database itself is set to accept null and is not primary or unique.</p>