Re: Creating variable names from values
| From: | Richard Lynch | Date: | Tue, 13 Mar 2007 00:30:04 +0000 |
| Subject: | Re: Creating variable names from values | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-250363@lists.php.net to get a copy of this message | ||
On Thu, March 8, 2007 11:56 am, Otto Wyss wrote:
> From an arry I create a table like
>
> foreach ($persons as $key => $pers) {
> echo "<td><input name=\"K$key\" type=\"checkbox\"
> ...></td>
> <td>...</td>
> }
>
> so each checkbox field has its own name created from $key. Yet how can
> I
> access these fields (names) later on?
>
> foreach ($persons as $key => $pers) {
> if ($K???) {
> $cnt += 1; ...
> }
> }
This is where you use variable variables when you don't know that you
shouldn't have done that...
> Is there a better way to access multiple fields from a table?
Use arrays.
<input name="K[<?php echo $key?>]" value="<?php echo $K[$key]?>"
/>
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?