Given the following two indexed arrays:
给定以下两个索引数组:
$a = array('a', 'b', 'c');
$b = array('red', 'blue', 'green');
What is the most straighforward/efficient way to produce the following associative array?:
生成以下关联数组的最直接/最有效的方法是什么?:
$result_i_want = array('a' => 'red', 'b' => 'blue', 'c' => 'green');
Thanks.
谢谢。
2 个解决方案
#2
2
This should do it:
这应该这样做:
$a = array('a', 'b', 'c');
$b = array('red', 'blue', 'green');
$c = array_combine($a, $b);
print_r($c);
Result:
结果:
Array
(
[a] => red
[b] => blue
[c] => green
)
#1
#2
2
This should do it:
这应该这样做:
$a = array('a', 'b', 'c');
$b = array('red', 'blue', 'green');
$c = array_combine($a, $b);
print_r($c);
Result:
结果:
Array
(
[a] => red
[b] => blue
[c] => green
)