PHP如何将2个单独的字符串转换为关联数组(如索引和值) [英] PHP How Do I Convert 2 Separate Strings Into An Associative Array (as Index & Value)

查看:121
本文介绍了PHP如何将2个单独的字符串转换为关联数组(如索引和值)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个字符串变量:

$names = "Sean Connery,George Lazenby,Roger Moore,Timothy Dalton,Pierce,Brosnan,Daniel Craig";
 $movies = "Dr. No/On Her Majesty's Secret Service/Live and Let Die/The Living Daylights/GoldenEye/Casino Royal";

我需要将这两个字符串转换为关联数组,并以$names作为index$movies作为values.我该怎么办?

I need to convert these two strings into an associative array with $names as the index and $movies as the values. How would I do this?

推荐答案

我会这样处理:

$array = array_combine(explode(',',$names),explode('/',$movies));

这篇关于PHP如何将2个单独的字符串转换为关联数组(如索引和值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆