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:
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));