[英]What's the most straightforward way in PHP to create an associative array from two parallel indexed arrays?
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. 谢谢。
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
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.