linux以冒号分割得到数组,siredHow我可以拆分一个逗号分隔的字符串到一个数组中,并再次在PHP中通过冒号拆分该数组?...

我有一个字符串,用逗号分隔。我用爆炸来通过逗号分隔它,这给了我作为数组的结果。在那个数组中,我有需要被分隔的数据:。我该如何实现这个?以下是字符串和输出。任何帮助...提前感谢。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 tablespoon

2015-09-20

Snehal

+1

'$输出= explode(',',$ ing); array_walk($ output,function(&$ value){$ value = explode(':',$ value);});' –

+0

你想要最终结果全部在一维数组中还是可以array [0]是第二次爆炸后的数组? –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值