Solved

PHP foreach loop problem.

Posted on 2009-04-15
3
195 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
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 16

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now