我已經設置了一組複選框。它們是動態的,所以複選框的數量將根據使用該網站的人而不同。如何創建複選框的結構是:將複選框值傳遞給數組?
<label for="plabackformat-holder-label">Format</label>
<div class=" playbackformat-holder-<?php echo $num; ?> playbackformat-holder">
<div class="playback-format-radio-buttons">
<label for="notset-<?php echo $num; ?>">
<input type="checkbox" class="playbackformat-holder-radiobutton" value="notset" name="playback_format[<?php echo $second_num; ?>]" id="notset-<?php echo $num; ?>" <?php if($field['playback_format'] == 'notset') { echo 'checked'; } ?>>None
</label>
<label for="dvd-<?php echo $num; ?>">
<input type="checkbox" class="playbackformat-holder-radiobutton" value="dvd" name="playback_format[<?php echo $second_num; ?>]" id="dvd-<?php echo $num; ?>" <?php if($field['playback_format'] == 'dvd') { echo 'checked'; } ?>>DVD
</label>
<label for="bluray-<?php echo $num; ?>">
<input type="checkbox" class="playbackformat-holder-radiobutton" value="bluray" name="playback_format[<?php echo $second_num; ?>]" id="bluray-<?php echo $num; ?>" <?php if($field['playback_format'] == 'bluray') { echo 'checked'; } ?>>Bluray
</label>
<label for="3d-<?php echo $num; ?>">
<input type="checkbox" class="playbackformat-holder-radiobutton" value="3d" name="playback_format[<?php echo $second_num; ?>]" id="3d-<?php echo $num; ?>" <?php if($field['playback_format'] == '3d') { echo 'checked'; } ?>>3d
</label><br />
</div>
</div>
我保存功能是:
$new = array();
for ($i = 0; $i < $count; $i++) {
$new[$i]['playback_format'] = $playbackFormats[$i];
}
我已經在這個問題上讀了,似乎它的,因爲我的輸入字段不包含唯一名。我試圖將數據存儲到數組中,所以它會是['playback_format'] => dvd,3d,bluray
或類似的東西。
現在它只存儲上次選中的值。有沒有一種方法,我可以使用forloop或其他東西迭代檢查值並將它們推入我的數組?