Logic - checking if at least one field is not zero
I have this code and need help with the logical ending. I would like at least one field not to be null.
if(!empty($fileTypes) || !empty($fileSizes) || !empty($fileUploads) || !empty($features) || !empty($design) || !empty($other) || !empty($contact)) {
} else {
$error = 1;
}
+3
droidus
source
to share
1 answer
Yes, sorry for the following work:
$array = array();
if($_POST){
foreach ($_POST as $key => $value){
if (!empty($value)){
$array[$key] = $value;
}
}
if (empty($array))
{
echo 'array empty';//throw error
} else {
echo 'array not empty'; //there is a submission
}
}
EDIT: missed the closing tag in paste .... fixed
+1
Zac
source
to share