From b5172ff53a637d01872b7d90899ee64472ee2e92 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 18 Dec 2025 11:50:14 +0100 Subject: [PATCH] wip #7904 @1 --- src/ArrayUtil.php | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/ArrayUtil.php b/src/ArrayUtil.php index 51db0ed..8a311cc 100644 --- a/src/ArrayUtil.php +++ b/src/ArrayUtil.php @@ -165,16 +165,42 @@ class ArrayUtil public static function merge() { $args = func_get_args(); - $res = array(); + $res = []; foreach ($args as $arg) { if (!is_array($arg)) { - $arg = array($arg); + $arg = [$arg]; } $res = array_merge($res, $arg); } return $res; } + public static function mergeOverwriteNull() + { + $args = func_get_args(); + foreach ($args as $k => $arg) { + self::cleanNullValues($arg); + $args[$k] = $arg; + } + return call_user_func_array('self::merge', $args); + } + + public static function cleanNullValues(&$arr) + { + foreach ($arr as $k => $v) { + if (is_array($v)) { + self::cleanNullValues($v); + if (!count($v)) { + unset($arr[$k]); + } else { + $arr[$k] = $v; + } + } else if (null === $v) { + unset($arr[$k]); + } + } + } + /** * @param $str * @return int[] -- 2.39.5