tags:

views:

82

answers:

2

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.

+18  A: 

array_combine

In your case:

$result_i_want = array_combine($a, $b);
Artefacto
Learn something new every day. I've done PHP for six years and never heard of that function.
Jarrod
+2  A: 

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
)
Sarfraz