tags:

views:

115

answers:

2

Hello,

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 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!

+1  A: 

Use:

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

This shall create an array of the selected values.

nikic
thank you very much!
behrk2
A: 

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>
Māris Kiseļovs