I think you can use array_filter function to remove null values in both array and then merge them
$a = array(
'a' => NULL,
'b' => 1,
'c' => 1
);
$b = array(
'a' => 1,
'b' => NULL,
'c' => 1
);
$b = array_filter($b);
$a = array_filter($a);
$c = array_merge($a, $b);
var_dump($c);
This will output
array(3) {
["b"]=> int(1)
["c"]=> int(1)
["a"]=> int(1)
}
LIVE SAMPLE
As side note i would add that using array_filter without second parameter will end up in deleting all NULL values as well as EMPTY array etc. If you want to only remove NULL values so you will need to use array_filter($yourarray, 'strlen');
EDITED
If you want to preserve NULL if both arrays have it with the same key and supposing that both arrays have same number of keys/values, then you will need to loop inside your array and build a new array preserving NULL where you need
$a = array(
'a' => NULL,
'b' => 1,
'c' => 1,
'd' => NULL
);
$b = array(
'a' => 1,
'b' => NULL,
'c' => 1,
'd' => NULL,
);
$c = array();
foreach($a as $key => $val)
{
if($key == NULL && $b[$key] == NULL)
{
$c[$key] = $val;
} else if($key != NULL && $b[$key] == NULL) {
$c[$key]= $val;
} else if($key != NULL && $b[$key] != NULL) {
$c[$key]= $b[$key];
} else {
$c[$key]= $b[$key];
}
}
var_dump($c);
This will output
array (size=4)
'a' => int 1
'b' => int 1
'c' => int 1
'd' => NULL
LIVE SAMPLE