• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 221
  • Last Modified:

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
0
Chimeraza
Asked:
Chimeraza
1 Solution
 
hernst42Commented:
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now