我有一个字符串,用逗号分隔。我用爆炸来通过逗号分隔它,这给了我作为数组的结果。在那个数组中,我有需要被分隔的数据:。我该如何实现这个?以下是字符串和输出。任何帮助...提前感谢。siredHow我可以拆分一个逗号分隔的字符串到一个数组中,并再次在PHP中通过冒号拆分该数组?
字符串:
$ing= 'coconut water :3-4 cups, coconut flesh : ½ cup, tea :4 tablespoon, Ice cubes :24-32, Lemon juice :4 tablespoon, Honey :8 tablespoon'
$output = explode(',', $ing);
输出:
Array ([0] => coconut water :3-4 cups
[1] => coconut flesh : ½ cup
[2] => tea :4 tablespoon
[3] => Ice cubes :24-32
[4] => Lemon juice :4 tablespoon
[5] => Honey :8 tablespoon)
现在,我想单独椰子水:3-4杯的结肠。
编辑:
$ing= 'coconut water :3-4 cups, coconut flesh : ½ cup, tea :4 tablespoon, Ice cubes :24-32, Lemon juice :4 tablespoon, Honey :8 tablespoon'
$output1 = explode(',', $ing);
$output=array();
foreach($output1 as $item){
$output[]=explode(':', $item);
}
输出:
Array
(
[0] => Array
(
[0] => coconut water
[1] => 3-4 cups
)
[1] => Array
(
[0] =>
coconut flesh
[1] => ½ cup
)
[2] => Array
(
[0] =>
tea
[1] => 4 tablespoon
)
[3] => Array
(
[0] =>
Ice cubes
[1] => 24-32
)
[4] => Array
(
[0] =>
Lemon juice
[1] => 4 tablespoon
)
[5] => Array
(
[0] =>
Honey
[1] => 8 tablespoon
)
)
所需的输出:
coconut water 3-4 cupscoconut flesh½ cuptea 4 tablespoonIce cubes24-32Lemon juice4 tablespoonHoney8 tablespoon2015-09-20
Snehal
+1
'$输出= explode(',',$ ing); array_walk($ output,function(&$ value){$ value = explode(':',$ value);});' –
+0
你想要最终结果全部在一维数组中还是可以array [0]是第二次爆炸后的数组? –