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.
array_combine
In your case:
$result_i_want = array_combine($a, $b);
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
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With