我有 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!"}
最有效的方法是什么?谢谢
采用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);
您是否尝试过使用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);