将分隔字符串拆分为键值对
如何内爆 2 个值,1 个作为键,另一个作为值。假设我有:
$string = 'hello_world';
$arg = explode('_', $string);
我现在有 $arg[0]
和 $arg[1]
(如你所知)
我怎样才能将其内爆,使其变成这种结构
Array (
'hello' => 'world'
)
How do I implode 2 values, 1 as the key and the other as the value. Say I have:
$string = 'hello_world';
$arg = explode('_', $string);
I now have $arg[0]
and $arg[1]
(as you know)
How can I implode that so it becomes this structure
Array (
'hello' => 'world'
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是一种无需使用中间参数即可完成此操作的有趣方法;)
Here's a fun way to do it without using intermediate args ;)
我不确定您是否正在寻找如此明显的东西:
我认为它比这更复杂一点。也许该字符串包含多个这样的东西。例如:'hello_world,foo_bar,stack_overflow'。在这种情况下,您需要先用逗号进行爆炸:
I'm not sure if you're looking for something this obvious:
I assume it's a bit more complicated than this. Maybe the string contains multiple of these things. ex: 'hello_world,foo_bar,stack_overflow'. In which case you'd need to explode by the comma first:
将是最快的方法
would be the quickest way