Solved

PHP foreach loop problem.

Posted on 2009-04-15
3
206 Views
Last Modified: 2012-05-06
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
Comment
Question by:Chimeraza
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 250 total points
ID: 24148616
you can't combine empty with a function call. See http://www.php.net/empty Use as condition:
trim($_POST[$value]) == ''
0
 
LVL 17

Expert Comment

by:Chris Harte
ID: 24148723
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
 
LVL 3

Author Closing Comment

by:Chimeraza
ID: 31570465
First come first serve! Thanks
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question