Reply to Re: [PHP] can I do a for each here??

Your name:

Reply:


Posted by Marek Kilimajer on 03/17/05 15:19

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]", "");
}
}

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация