Re: can I do a for each here??
| From: | Marek Kilimajer | Date: | Thu, 17 Mar 2005 13:19:26 +0000 |
| Subject: | Re: can I do a for each here?? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-210975@lists.php.net to get a copy of this message | ||
AndreaD wrote:
I have about 10 text boxes each taking in value (ages) , The code I have checks for a value and if it is set it then sets the cookie to that value. The else just clears the value. On the next page I use a foreach to get the values but I think there must be a quicker way to collect the data appart from 10 if-else staements. if (isset($andrea){ setcookie("cookie[andrea]", "$andrea"); } else {setcookie("cookie[$andrea]", ""); } if (isset($james){ setcookie("cookie[james]", "$james"); } else {setcookie("cookie[$james]", ""); }$names = array('andrea', 'james', ...); foreach($names as $name) { if (isset($_POST[$name]){
setcookie("cookie[$name]", $_POST[$name]);
} else {
setcookie("cookie[$name]", "");
}
}