Chimeraza
asked on
PHP foreach loop problem.
Can you help me sort out this function... $field is an array of field names that need to be checked.
For example:
$field = ['cus_id', 'cus_fname', 'cus_sname']
function isEmpty($field, $msg = NULL)
{
if ($msg == NULL) {$msg = 'Field Empty';}
foreach($field as $key => $value) {
if(!isset($_POST[$value]) || (empty(trim($_POST[$value] ))))
{
$this->_errorList[] = array("field" => $value, "msg" => $msg);
return false;
}
else
{
return true;
}
}
}
I am getting this error:
Fatal error: Can't use function return value in write context
Thanks
Nick
For example:
$field = ['cus_id', 'cus_fname', 'cus_sname']
function isEmpty($field, $msg = NULL)
{
if ($msg == NULL) {$msg = 'Field Empty';}
foreach($field as $key => $value) {
if(!isset($_POST[$value]) || (empty(trim($_POST[$value]
{
$this->_errorList[] = array("field" => $value, "msg" => $msg);
return false;
}
else
{
return true;
}
}
}
I am getting this error:
Fatal error: Can't use function return value in write context
Thanks
Nick
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
empty() only works on variables. trim() returns a string. I think that is your problem. Try it with strlen instead of empty. If I am write that will cure your problem.
ASKER
First come first serve! Thanks