php codeigniter中的explode()函数错误

时间:2017-09-21 06:06:36

标签: php codeigniter

我已经通过用逗号分隔将值存储到数据库中,现在我想在这里分隔每个值。我尝试使用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>

3 个答案:

答案 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 )