A possibility would be:
$array = array(
'bla' => (isset($array2['bla']) ? $array2['bla'] : ''),
'bla2' => (isset($array2['bla2']) ? $array2['bla2'] : ''),
'foo' => (isset($array2['foo']) ? $array2['foo'] : ''),
'xxx' => (isset($array2['yyy']) ? $array2['yyy'] : ''),
'bar' => (isset($array2['bar']) ? $array2['bar'] : '')
);
If this shoud happen more dynamically, I would suggest to use array_intersect_key, like soulmerge posted. But that approach would have the tradeoff that only arrays with the same keys can be used.
Since your keys in the 2 arrays can vary, you could build something half-dynamic using a mapping array to map the keys between the arrays. You have at least to list the keys that are different in your arrays.
//key = key in $a, value = key in $b
$map = array(
'fooBar' => 'bar'
);
$a = array(
'fooBar' => 0,
'bla' => 0,
'xyz' => 0
);
$b = array(
'bla' => 123,
'bar' => 321,
'xyz' => 'somevalue'
);
foreach($a as $k => $v) {
if(isset($map[$k]) && isset($b[$map[$k]])) {
$a[$k] = $b[$map[$k]];
} elseif(isset($b[$k])){
$a[$k] = $b[$k];
}
}
That way you have to only define the different keys in $map.