PHP excluding specific variable values from foreach statement -


i trying exclude fields form being required. entire array payment runs through each statement. trying keep fields extra, extra2 , extra3 being required. can set null or defined whatever string if empty. have currently:

  foreach($p $key => $value) {     $value = trim($value);     if($value == '') {       $keyname = preg_replace('/([a-z])/', " $1", $key);       $this->_errors['payment ' . $keyname] = __('payment ','cart66') . $keyname . __(' required','cart66');       $this->_jqerrors[] = "payment-$key";     } 

this have tried, no avail:

 foreach($p $key => $value) {     $value = trim($value);     if($value == '' && $p != 'extra' || 'extra2' || 'extra3') {       $keyname = preg_replace('/([a-z])/', " $1", $key);       $this->_errors['payment ' . $keyname] = __('payment ','cart66') . $keyname . __(' required','cart66');       $this->_jqerrors[] = "payment-$key";     } else if ($p['extra'] == '') {  $_p['extra'] = null;  } else if ($p['extra2'] == '') {  $_p['extra2'] = null;  } else if ($p['extra3'] == '') {  $_p['extra3'] = null;  } 

}

it's syntax isn't it? database set accept null , not primary or unique.

one way check @ top of loop , continue if you're in on field should excluded.

$exclude = array('field1', 'field2', ...); foreach ($p $key => $value) {     if (in_array($key, $exclude)) { continue; }      // code...  } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -