I have an array holding some default settings for my plugin. As the plugin evolves settings maybe removed or added from version to version.
Here is an example default array:
$defaults = array(
'setting1' => 'somevalue',
'setting2' => 'somevalue',
'setting4' => 'somevalue',
);
Here is an example of live settings data that the structure needs to be updated for the new $default structure:
$livesettings = array(
'setting1' => 'foo',
'setting2' => 'bar',
'setting3' => 'foobar',
);
I'm looking for a function where I can pass both arrays and the structure of the livesettings is updated to match the $defaults.
So in this case in livesettings:
- setting1 and setting2 isn't touched. Their values stay intact
- setting3 is removed as no longer needed
- setting4 is added with the default value of
somevalue
Are their any functions in PHP that can do this in one go? If yes what is it? If no how would I achieve this with PHP code?