3v4l.org

run code in 300+ PHP versions simultaneously
<?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);
Output for git.master, git.master_jit, rfc.property-hooks
array(2) { ["2020-12"]=> array(4) { ["Mois"]=> string(7) "2020-12" ["number"]=> string(1) "1" ["Nbr vendus"]=> string(1) "1" ["CA TTC"]=> string(3) "790" } ["2021-01"]=> array(4) { ["Mois"]=> string(7) "2021-01" ["number"]=> string(1) "2" ["Nbr vendus"]=> string(1) "3" ["CA TTC"]=> string(4) "1680" } }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
60.19 ms | 402 KiB | 8 Q