问题
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