PHP 如何将 2 个单独的字符串转换为关联数组(作为索引和值)
PHP How Do I Convert 2 Separate Strings Into An Associative Array (as Index & Value)
我有两个字符串变量:
$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
。我该怎么做?
我会这样做:
$array = array_combine(explode(',',$names),explode('/',$movies));
我有两个字符串变量:
$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
。我该怎么做?
我会这样做:
$array = array_combine(explode(',',$names),explode('/',$movies));