dsqdpn31467 2014-03-03 09:29
浏览 34
已采纳

PHP使用2种类型的分隔符爆炸数组

I have this options array:

string(111) "colors:black;white;transparent;pink;"    

how can I explode it so I get as a label first separator : and the rest in array as options? I have this so far:

$options= explode(";",$rows[0]);
$htm= '<ul class="product_opts">'.$lang['available_options'].'';
foreach ($options as $value) { 
        $row=mysql_fetch_row($result);
            $htm.='<li style="text-align:left;font-weight:normal;">'.$value.'</li>';
            }
        $htm.= '</ul>';
        }
    echo $htm;    

but it returns the label as option too..

  • 写回答

5条回答 默认 最新

  • duanjiu4498 2014-03-03 09:35
    关注
    $str = "colors:black;white;transparent;pink;";
    
    list($label, $optionsStr) = explode(":", $str);
    
    $optionsStr = rtrim($optionsStr, ";");
    $options = explode(";", $optionsStr);
    
    echo "<pre>";
    print_r($label);
    
    print_r($options);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题