<?php
function array_remove_null($input) {
foreach ($input as &$value) {
if (is_array($value)) {
$value = array_remove_null($value);
}
}
return array_filter($input, function($item){
return $item !== null && $item !== '';
});
}
/**
* Using https://www.php.net/manual/en/function.array-replace-recursive.php
*/
$array1 = [
"2020-12" => [
"Mois" => "2020-12",
"Nbr vendus" => null,
"CA TTC" => null,
"number" => "1",
],
"2021-01" => [
"Mois" => "2021-01",
"Nbr vendus" => null,
"CA TTC" => null,
"number" => "2",
],
];
$array2 = [
"2020-12" => [
"Mois" => "2020-12",
"Nbr vendus" => "1",
"CA TTC" => "790",
"number" => null,
],
"2021-01" => [
"Mois" => "2021-01",
"Nbr vendus" => "3",
"CA TTC" => "1680",
"number" => null,
],
];
$array = array_replace_recursive(array_remove_null($array1), array_remove_null($array2));
var_dump($array);
preferences:
26.9 ms | 402 KiB | 5 Q