Re: dealing with arrays
| From: | Curt Zirzow | Date: | Wed, 27 Aug 2003 21:09:02 +0000 |
| Subject: | Re: dealing with arrays | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-160962@lists.php.net to get a copy of this message | ||
* Thus wrote Ford, Mike [LSS] (M.Ford@lmu.ac.uk):
> On 27 August 2003 04:22, Aris Santillan wrote:
>
> > I Have
> > <p>Entry One
> > <input type=text name=name[]>
> > <input type=text name=tel[]>
> > <input type=checkbox name=check[] value=1>
>
> The way to combat this is to use explicit subscripts in your form field names, like so:
>
> <p>Entry One
> <input type=text name=name[1]>
> <input type=text name=tel[1]>
> <input type=checkbox name=check[1] value=1>
I would also add some structure to avoid all the different
variables and makes looping much smoother on the processing script.
<input type=text name="elements[2][name]">
<input type=text name="elements[2][tel]">
<input type=checkbox name="elements[2][checked]" value="1">
Then:
foreach ($_REQUEST['elements'] as $id => $element) {
if ($element['checked']) {
// its checked
} else {
// not checked.. duh..
}
}
Curt
--
"I used to think I was indecisive, but now I'm not so sure."