Suppose the arrays below:
$arr1 = [
'aa' => 0,
'bb' => 5,
'cc' => 0,
'dd' => 2,
];
$arr2 = [
'bb' => 5,
'cc' => 7,
'dd' => 2,
];
I need an elegant, one-liner, that will add the values of the second array to the values of the first array with the same keys.
Something like this:
foreach ( $arr1 as $key => $val ) {
if ( isset( $arr2[$key] ) ) $arr1[$key] = $val + $arr2[$key];
}
but more elegant, and preferably one-liner.
Example: https://onlinephp.io/c/0bc42