我已经通过用逗号分隔将值存储到数据库中,现在我想在这里分隔每个值。我尝试使用implode函数,但它只显示第一个值。请帮忙。
<div class="col-md-12">
<label for="#" class="col-sm-2 control-label">Facilities</label>
<div class="col-sm-6">
<div class="col-sm-6 checkbox"><input id="checkbox5" type="checkbox" name="facilities[]" value="1"
<?php
if ( isset($selectdata))
{
foreach($selectdata as $r )
{
$i = explode(',',$r->facilities);
echo set_value('facilities[]',$i) == 1 ? "checked" : "";
}
}
?>
><label for="checkbox5" >Guide</label></div>
<div class="col-sm-6 checkbox"><input id="checkbox1" type="checkbox" name="facilities[]" value="2"><label for="checkbox1">Site Seeing</label></div>
<div class="col-sm-6 checkbox"><input id="checkbox2" type="checkbox" name="facilities[]" value="3"><label for="checkbox2">Hotel</label></div>
<div class="col-sm-6 checkbox"><input id="checkbox2" type="checkbox" name="facilities[]" value="4"><label for="checkbox3">Travel</label></div>
<div class="col-sm-6 checkbox"><input id="checkbox2" type="checkbox" name="facilities[]" value="5"><label for="checkbox4">Food</label></div>
</div>
</div>
答案 0 :(得分:0)
替换以下代码
$i = explode(',',$r->facilities);
与
$i = explode(',',$r->facilities]);
答案 1 :(得分:0)
请你替换
$i = explode(',',$r->facilities]);
到
$i = explode(',',$r->facilities);
因为它有一个额外的括号(])。
答案 2 :(得分:0)
implode
用于将数组分组回单个字符串。 explode
用于将字符串分隔为数组。
$string = 'hello how are you,are you ok';
$explode = explode(',', $string);
print_r($explode);
//Result: Array ( [0] => hello how are you [1] => are you ok )