I think you are looking for array_replace_recursive , especially for the case when your "defaults" can be an associative array with a depth of more than one level.
$finalArray = array_replace_recursive(array $defaults, array $inputOptions)
Here is an example that takes an optional array of options for a function and does some processing based on the result of the opts and defaults options that you specify:
function do_something() { $args = func_get_args(); $opts = $args[0] ? $args[0] : array(); $defaults = array( "second_level" => array( "key1" => "val1", "key2" => "val2" ), "key1" => "val1", "key2" => "val2", "key3" => "val3" ); $params = array_replace_recursive($defaults, $opts);
Php.net help document here here
Augie gardner
source share