php将数组中的键移动到另一个数组中

时间:2014-02-19 14:44:08

标签: php arrays key

所以我有这个数组:

[0] => 3
[1] => 9
[2] => 4
[3] => 6
[4] => 69
[5] => 8
[6] => 9
[7] => 12
[8] => 9
[9] => 7

这一个

[Far] => 1
[far] => 3
[away] => 1
[behind] => 1
[the] => 23
[word] => 2
[mountains] => 1
[from] => 3
[countries] => 1
[Vokalia] => 1

我希望第一个数组的值将覆盖第二个数组的值而不更改第二个数组的键。 我已经尝试摆弄foreach功能,但没有优势。 所以最后我希望它看起来像这样:

[Far] => 3
[far] => 9
[away] => 4
[behind] => 6
[the] => 69
[word] => 8
[mountains] => 9
[from] => 12
[countries] => 9
[Vokalia] => 7

有谁知道怎么做?如果是的话,那个人可以在foreach函数中提供更多信息吗?

1 个答案:

答案 0 :(得分:5)

假设您的数组是$array1$array2

$keys = array_keys($array2);
$result = array_combine($keys, $array1);

文档:

Online demo