explode()变成$ key => $ value对 [英] explode() into $key=>$value pair
本文介绍了explode()变成$ key => $ value对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个:
$strVar = "key value";
我想在这里得到它:
array('key'=>'value')
我用explode()尝试过,但这给了我:
I tried it with explode(), but that gives me this:
array('0' => 'key',
'1' => 'value')
原始的$ strVar已经是爆炸字符串的结果,我正在遍历结果数组的所有值.
The original $strVar is already the result of an exploded string, and I'm looping over all the values of the resulting array.
推荐答案
不相信通过一次操作就可以做到这一点,但这应该可以解决问题:
Don't believe this is possible in a single operation, but this should do the trick:
list($k, $v) = explode(' ', $strVal);
$result[ $k ] = $v;
这篇关于explode()变成$ key => $ value对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文