PHP How Do I Convert 2 Separate Strings Into An Associative Array (as Index & Value)

主宰稳场 提交于 2020-11-29 23:57:04

问题


I have two string variables:

$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";

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?


回答1:


I would do it with something like this:

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


来源:https://stackoverflow.com/questions/29594500/php-how-do-i-convert-2-separate-strings-into-an-associative-array-as-index-va

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!