0

我有两个关联数组,我希望与 foreach 循环结合:

$arr1 = array( 'wikipedia.org' => 11, 'bing.com' => 9, 'google.com' => 8, 'blekko.com' => 7, 'groove.com' => 6, 'blo.com' => 5, 'ekko.com' => 4, 'rokko.com' => 3, 'always.com' => 2, 'popo.com' => 1);
$arr2 = array( 'google.com' => 20, 'blekko.com' => 19, 'wikipedia.org' => 8, 'bing.com' => 7, 'blo.com' => 6, 'ekko.com' => 5, 'groove.com' => 4, 'popo.com' => 3, 'always.com' => 2, 'rokko.com' => 1);

我使用一个新数组

$combined = $arr1;

带有 foreach 循环

foreach($arr2 as $key=>$value)
{
    array_push($combined,$value); 
}

...这增加了价值但不是关键。我想我知道为什么,但找不到添加键和值的方法。这适用于单行,但令人沮丧的是,在 foreach 循环中也不行!

$combined=array_merge(array('blovk.com'=>'44'),$combined); 
4

1 回答 1

5

$aggregatedResults[$key] = $value;

应该就是这么简单...

于 2013-06-19T16:36:04.477 回答