我有一个for-each循环,该循环在编辑模式下填充多个select选项标签,我想选择存储在数据库中的selected选项。
来自数据库的值在内部爆炸,如下所示:
$f_r = explode(",",$user['field']);
这是我的选择创建:
<?php foreach ($fields as $field) : ?>
<option value="<?= $field['field_name'] ?>" style="direction: rtl" ><?= $field['field_name'] ?></option>
<?php endforeach; ?>
如何从$f_r值中选择值?
我已经试过了这段代码,并且得到了结果,但是根据数组结果,我的选项标签中的列表已经倾斜:
<select class="selectpicker form-control" name="field[]" id="field" multiple data-live-search="true">
<?php $f_r = explode(",",$user['field']); ?>
<!-- Array ( [0] => נדלן פרוייקטים [1] => נדלן פרטי [2] => נדלן פרטי ומסחרי )-->
<?php foreach ($fields as $field) : ?>
<?php foreach ($f_r as $f) : ?>
<option value="<?= $field['field_name'] ?>" style="direction: rtl" <?php if($f == $user['field']){echo 'selected';} ?> ><?= $field['field_name'] ? </option>
<?php endforeach; ?>
<?php endforeach; ?>
</select>
没有选项重复怎么办?
函数式编程