开发者

Dynamic combo box name as a php array

I am dynamically creating combo boxes with PHP for a calendar:

<?php $i=1; while($i <= $daysInMonth){?>
<table align="center" style="width: 435px">
    <tr>
        <td class="style1"><p><label id="<?php echo($month.'-'.$i); ?>"><?php echo($month.' '.$i); ?></label>&nbsp;</p></td>
        <td class="style1"><p><select name="<?php echo($i); ?>" multiple="multiple">
        <?php foreach($email_array as $arr){ ?>
            <option><?php echo($arr); ?></option>
        <?php } ?>
        </select></p></td>
    </tr>
</table>

Each combo box name corresponds with the day of the month. For each day of month, I want to provide the ability to assign multiple names. I have been able开发者_JAVA技巧 to achieve this except for the fact that I cannot get multiple names from each combo box, only one. This is because the combo box is named as:

<select name="<?php echo($i); ?>

Instead, I need the name to be an array. How can put a name in the array and at the same time keep the days of the week ($i) in place?

Thanks!


Use:

name="<?php echo($i); ?>[]"

This shall create an array of the selected values.


To specify elements name as array you can write "name[]" instead of "name". For example:

<select name="day[<?php echo($i); ?>][]"> ... </select>

In PHP it will result as multidimensional array with first key "day", then day of the week and select's number at last.

OR:

<select name="<?php echo($i); ?>[]"> ... </select>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜