I have two associative arrays I wish to combine with a foreach loop:
$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);
I use a new array
$combined = $arr1;
with a foreach loop
foreach($arr2 as $key=>$value)
{
array_push($combined,$value);
}
... which adds the value but not the key. I think I know why, but cannot find a way to add the key and the value. This works for a single line, but frustratingly nor in a foreach loop!
$combined=array_merge(array('blovk.com'=>'44'),$combined);
$aggregatedResults[$key] = $value;
It should be that simple...