我有两个数组,一个带键,另一个带值:
key_array = ['key1','key2','key3']
values_array = ['val1','val2','val3']
如何迭代它们(它们的大小会有所不同)来获得这个:
array('key1' => 'val1',
'key2' => 'val2',
'key3' => 'val3')
答案 0 :(得分:1)
$a = array('green', 'red', 'yellow');
$b = array('avocado', 'apple', 'banana');
$c = array_combine($a, $b);
print_r($c);
?>
Array
(
[green] => avocado
[red] => apple
[yellow] => banana
)