-2

我有 2 个数组:

1st array {0=> "google", 1=> "apple", 2=> "microsoft"}
2nd array {0=> "awesome", 1=> "sucks", 2=> "oh man!"}

现在我想要以这种形式合并 2 个数组:

array {"google"=>"awesome", "apple"=>"sucks", "microsoft"="oh man!"}

最有效的方法是什么?谢谢

4

2 回答 2

3

采用array_combine — Creates an array by using one array for keys and another for its values

$a = array(0=> "google", 1=> "apple", 2=> "microsoft");
$b = array(0=> "awesome", 1=> "sucks", 2=> "oh man!");

$c = array_combine($a, $b);

print_r($c);
于 2013-04-01T05:29:06.293 回答
0

您是否尝试过使用array_combine ..??像这样尝试

$array3 = array_combine($array1, $array2); 
print_r($array3);

你会喜欢

array {"google"=>"awesome", "apple"=>"sucks", "microsoft"="oh man!"}

您也可以尝试使用“ array_merge

$array3 = array_merge($array1, $array2);
print_r($array3);
于 2013-04-01T05:31:48.437 回答