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
LVL 3
ChimerazaAsked:
Who is Participating?
 
hernst42Connect With a Mentor Commented:
you can't combine empty with a function call. See http://www.php.net/empty Use as condition:
trim($_POST[$value]) == ''
0
 
Chris HarteThaumaturgeCommented:
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.
0
 
ChimerazaAuthor Commented:
First come first serve! Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.