Well… with this example, yeah, I guess so. This is more simplistic than I thought it was.
Take these arrays as an example:
$a1 = array(
"one"=>"hello",
"two" => array( "hello" );
);
$a2 = array(
"one"=>"goodbye",
"two" => array( "goodbye" )
);
with array_merge_recursive, you'll get:
array(
"one" => array( "hello","goodbye" ),
"two" => array( "hello","goodbye" )
);
with array_replace_recursive:
array(
"one" => "goodbye",
"two" => array( "goodbye" )
);
…what I would want (in many cases, but especially for merging config arrays) would be something like this:
array(
"one" => "goodbye",
"two" => array( "hello","goodbye" )
);
Beyond my specific use case, it just seems more sensible to me. Here's the code I use to do that:
mergeRecursive( array $array1,array $array2 ){
$merged = $array1;
foreach( $array2 as $key => $value ){
if( isset( $merged[$key] ) ){
if( is_array( $value ) && is_array( $merged[$key] ) ){
$merged[$key] = mergeRecursive( $merged[$key], $value );
}
elseif( is_int( $key ) ){ $merged[] = $value; }
else{ $merged[$key] = $value; }
}
else{
$merged[$key] = $value;
}
}
return $merged;
}