Bluehost.com Web Hosting $6.95

Re: [PHP] foreach help

This is a discussion on Re: [PHP] foreach help within the PHP General forums, part of the PHP Programming Forums category; Well you could do foreach ( $_POST as $var ) ${$var} = ( isset($_POST[$var]) ? 1 : 0); but that's really sloppy. If ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-31-2003
Evan Nemerson
 
Posts: n/a
Default Re: [PHP] foreach help

Well you could do

foreach ( $_POST as $var )
${$var} = ( isset($_POST[$var]) ? 1 : 0);

but that's really sloppy. If possible, I'd go more for something like

$vars = Array(
'noPlatform',
'littlePlatform',
'lotsaPlatform',
'yoMommasaPlatform');

foreach ( $vars as $v ) {
${$v} = ( isset($_POST[$v]) ? 1 : 0 );
}



On Wednesday 30 July 2003 06:50 pm, Ryan A wrote:
> Hi,
> I have a set of checkboxes (around 38) which will be sent to me via a
> post(eg: <input name="noPlatform" type="checkbox" id="noPlatform"
> value="1>)...if the checkbox is checked then session "noPlatform" should be
> created...AND only the checked ones should be registered all others should
> be unset.
>
> one way to do this would be to something like this:
> $noPlatform = (isset($_POST['noPlatform'])) ? 1 : 0;
> then set the session or via using a if and isset...
>
> but that would mean doing that for the whole 38 fields...I think I have
> seen something like this done via a loop (for, while or foreach or a
> combination) but cant find it in my old mail or the archive.
>
> Thanks in advance,
> -Ryan


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 12:03 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0