I have two arrays:
Array
(
[2005] => 0
[2006] => 0
[2007] => 0
[2008] => 0
[2009] => 0
)
Array
(
[2007] => 5
[2008] => 6.05
[2009] => 7
)
I want to merge these two arrays such that if a value exists in the 2nd array, it overwrites the first array's value. So the resulting array would be:
Array
(
[2005] => 0
[2006] => 0
[2007] => 5
[2008] => 6.05
[2009] => 7
)
Thanks for your help.
UPDATE: This was my best attempt, but it's wildly unsuccessful:
$final = '';
foreach ($years as $k => $v){
if (in_array($k,$values)){
$final .= $values[$k] . '|';
}else{
$final .= $k[$v] . '|';
}
}
echo "final = $final";