note 30409 deleted from function.array-sum by didou
| From: | didou@php.net | Date: | Tue, 29 Jul 2003 11:46:16 +0000 |
| Subject: | note 30409 deleted from function.array-sum by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-52900@lists.php.net to get a copy of this message | ||
Note Submitter: office@at@universalmetropolis.com
----
A practical implementation of this function: creating a standardised error-checking process.
// check some fields
if(strlen(trim($username))<3){
$errormessage[]="You need to enter a username";
}else{
$errormessage[]=0;
}
if(strlen(trim($password))<3){
$errormessage[]="You need to enter a password";
}else{
$errormessage[]=0;
}
// check to see if there were any errors (an error-free submission will have a sum of 0)
if(array_sum($errormessage)!=0){
print "error!"; // (I use a separate error display function)
}else{
// no errors found, proceed with submission
}