我有这一行字符串
Fruits-banana|apple|orange:Food-fries|sausages:Desserts-ice cream|apple pie
:
(冒号)是主题的分隔符,|
是不同类型子主题的分隔符。
我尝试将其拆分成数组,并将其放入下拉菜单中显示:
水果 香蕉 苹果 橙子 食品 炸薯条 香肠
$result=explode(":",$data);
foreach($result as $res) {
$sub_res[]=explode("-",$res);
}
foreach($sub_res as $sub) {
//echo $sub[1]."<br>"; Over here, I can get the strings of [0]=>banana|apple|orange, [1]=>sausages|fries,
// I explode it again to get each items
$items[]=explode("|",$sub[1]);
$mainCategory[]=$sub[0]; // This is ([0]=>Fruits, ]1]=>Food, [2]=>dessert
// How do I assign the $items into respective categories?
}
谢谢!