我有一大段数据,用“,”分开,现在需要处理他,“,”为分割符,在每个数据前加上多选框,多选框id升幂排列

解决方案 »

  1.   

    $str = 'xxx';
    $arr = explode(',',$str);
    foreach($arr as $i=>$v){
      $arr[$i]='<input type="checkbox" id="'.$i.'" />'.$v
    }
    //到这里就可以了//如果要把数组转成字符串的话就接着:
    $out = implode($arr);
    echo $out ;
      

  2.   


    $str = 'xxx';
    $arr = explode(',',$str);
    foreach($arr as $i=>$v){
      $arr[$i]='<input type="checkbox" id="'.$i.'" />'.$v ;
    }
    //到这里就可以了//如果要把数组转成字符串的话就接着:
    $out = implode($arr);
    echo $out ;
      

  3.   

    $arr = explode(',',$str);
    sort($arr);//升序排序一下
    foreach($arr as $i=>$v){
      $arr[$i]='<input type="checkbox" id="'.$i.'" />'.$v ;
    }
    //到这里就可以了
      

  4.   


    $res  = $this->db_Scope1->get_scope_info($opts, $this->cache);   
                $list  = $this->db_Scope1->get_scope_list($opts, $this->cache);  
                $res['list_scope']= explode(',',$res['list_scope']);
    sort($res['list_scope']);
                foreach ($res['list_scope'] as $i=> $v)
    {
    $res[$i]='<input type="checkbox" id="'.$i.'" />'.$v ; }
    $res['list_scope'] = $list;
                var_dump($res['list_scope']);中间的$res['list_scope']);里面有个demand字段需要上述处理