I am trying to overwrite the elements of one array with values from another – without creating additional elements in the process.
For example:
$base = array('a' => 'apple', 'b' => 'banana');
$replace = array('a' => 'orange', 'b' => 'grape', 'c' => 'cauliflower');
Merge the arrays to create:
array('a' => 'orange', 'b' => 'grape'); // 'c' not included
Using array_merge or array_replace would properly overwrite the elements, but the resulting array would include elements not found in the first array.
How can I combine two arrays to create an array containing only keys from the first array, and the corresponding values from a second array?
Is there an existing PHP array function that can do this?
Thanks for your help!