Please help me with mapping array

I have an array like this
$mapping = [
‘campaigns’ => null,
‘campaignView’ => null,
‘campaignViewItems’ => null,
‘filters’ => [
‘content’ => [
‘start’ => null,
‘end’ => null,
‘channel’ => null,
‘topic’ => null
]
] ];

and 
        $test = [
              'campaigns' => [1,2,3],
              'filters' => [
                'content' => [
                    'channel' => [1,2,3],
                    'topic' => [10,11]
                ]
         ] 
        ];

I want to have a function map ( $test, $mapping), then i will fill all attribute that $test missing by null value from $mapping

The result should be:

array : [
‘campaigns’ => [1,2,3],
‘campaignView’ => null,
‘campaignViewItems’ => null,
‘filters’ => [
‘content’ => [
‘start’ => null,
‘end’ => null,
‘channel’ => [1,2,3],
‘topic’ => [10,11]
]
] ];

Something like:

function arrayMergeIfNotNull($arr1, $arr2) {
	foreach($arr2 as $key => $val) {
		$is_set_and_not_null = isset($arr1[$key]);
		if ( $val == NULL && $is_set_and_not_null ) {
			$arr2[$key] = $arr1[$key];
		}
	}
	return array_merge($arr1, $arr2);
}
var_dump(arrayMergeIfNotNull($mapping, $test));
		?>
Sponsor our Newsletter | Privacy Policy | Terms of Service