我在数据库中有一些项目,比如
Apple Juice;Orange Juice;Pineapple Juice;Cranberry Juice;Milk;
我如何拆分它们,以便每个都在PHP数组中
答案 0 :(得分:3)
这是你正在寻找的一个非常基本的explode function:
$yourString='Apple Juice;Orange Juice;Pineapple Juice;Cranberry Juice;Milk;';
$yourArray=explode(';',$yourString);
print_r($yourArray);
编辑:
要删除空数组字段,我们可以像这样使用array filter function:
$yourString='Apple Juice;Orange Juice;Pineapple Juice;Cranberry Juice;Milk;';
$yourArray=array_filter(explode(';',$yourString));
print_r($yourArray);
答案 1 :(得分:2)
$array = explode(";", "Apple Juice;Orange Juice;Pineapple Juice;Cranberry Juice;Milk");
答案 2 :(得分:0)
你可以这样做:
$items = explode(";", "Apple Juice;Orange Juice;Pineapple Juice;Cranberry Juice;Milk");
<pre>
print_r($items)
</pre>