2014-02-19 139 views
2

所以我有此數組:PHP移動鍵到另一個陣列

[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函數中工作的?

回答

5

假設你的數組是$array1$array2

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

文檔:

Online demo

+0

是的,謝謝!我也嘗試了array_combine,但是我在某個地方做錯了。謝了哥們。 – joster222

相關問題