foreach not working
Posted: Wed Nov 19, 2008 10:33 am
I'm having a problem getting this code to work in a foreach loop - perhaps someone can see what I'm not. In the if statement I have to use the names instead of the variable the names are asigned to :
this the way it should be, but it doesn't work--
this is what I've settled with -- it works
any suggestions would be greatly appreciated
this the way it should be, but it doesn't work--
Code: Select all
$required_fields = array('menu_name', 'position', 'visible');
foreach($required_fields as $fieldname) {
if(!isset($_POST[$fieldname]) ||
(empty($_POST[$fieldname]) && !is_int($_POST[$fieldname]))) {
$errors[] = $fieldname;
}
}Code: Select all
$required_fields = array('menu_name', 'position', 'visible');
foreach($required_fields as $fieldname) {
if(!isset($_POST['position']) ||
(empty($_POST['menu_name']) && !is_int($_POST['visible']))) {
$errors[] = $fieldname;
}
}