合并/更新具有重叠键的关联数组

I have two associative arrays with string keys, like this:

$base_array = array(
'foo' => '42',
'bar' => '13');

and

$update_array = array(
'bar' => '14',
'blah' => '3.1415');

Question 1: I want to update my $base_array with data from $update_array in such a way that:

  1. If a key is only in $base_array, but not in $update_array, its value be kept intact;
  2. If a key is in both arrays, its value be updated from $update_array;
  3. If a key is only in $update_array, both the key and its value be copied into $base_array.

Is there a short way to accomplish this? Any hint or piece of code is very welcome.

Question 2: Besides this, is there a quick way to visualize a joint list of keys from both arrays, without duplicates? Just keys, no values.

Question 1:

That is exactly what array_merge() does:

$new_array = array_merge($base_array,$update_array);

Question 2:

To get an array of the unique keys, you can merge the arrays and then use array_keys():

$keys = array_keys(array_merge($base_array,$update_array));