From: Vincent Vanwaelscappel Date: Thu, 18 Dec 2025 10:50:14 +0000 (+0100) Subject: wip #7904 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=b5172ff53a637d01872b7d90899ee64472ee2e92;p=cubist_util.git wip #7904 @1 --- 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[]