Append $old array by $new array (recursive) and override existing keys.

@param array $old
@param array $new

@return array
320386
public static function merge(array $old, array $new)
    {
        foreach ($new as $key => $value) {
            if (isset($old[$key]) && is_array($old[$key]) && is_array($value)) {
                $old[$key] = self::merge($old[$key], $value);
            } else {
                $old[$key] = $value;
            }
        }

        return $old;
    }
1258377
public function replace($old, $new)
    {
        $this->str = $this->str->replace((string)$old, (string)$new);

        return $this;
    }
296068
public function calculate(string $old, string $new): array
    {
        $olds = \preg_split('//uS', $old, -1, \PREG_SPLIT_NO_EMPTY);
        $news = \preg_split('//uS', $new, -1, \PREG_SPLIT_NO_EMPTY);

        // calculate edit distance matrix
        $dist = $this->calculateDistance($olds, $news);

        // calculate edit progresses
        $progresses = $this->calculateProgresses($olds, $news, $dist);

        return [
            // (int) Levenshtein distance
            'distance' => $dist[\count($olds)][\count($news)],
            // (null|array) edit progresses
            'progresses' => $progresses,
        ];
    }
747323
public static function mergeGroup($new, $old)
	{
		$new['namespace'] = static::formatUsesPrefix($new, $old);

		$new['prefix'] = static::formatGroupPrefix($new, $old);

		if (isset($new['domain'])) unset($old['domain']);

		$new['where'] = array_merge(array_get($old, 'where', []), array_get($new, 'where', []));

		return array_merge_recursive(array_except($old, array('namespace', 'prefix', 'where')), $new);
	}
1006521
public function rename($old, $new)
    {
        return ($this->isConnected() === true) ? ftp_rename($this->getConnection(), $old, $new) : false;
    }
452086
protected function mergeGroup(array $new, array $old)
    {
        $new['namespace'] = $this->formatNamespace($new, $old);

        $new['prefix'] = $this->formatPrefix($new, $old);

        foreach (['middleware', 'providers', 'scopes', 'before', 'after'] as $option) {
            $new[$option] = $this->formatArrayBasedOption($option, $new);
        }

        if (isset($new['domain'])) {
            unset($old['domain']);
        }

        if (isset($new['conditionalRequest'])) {
            unset($old['conditionalRequest']);
        }

        if (isset($new['uses'])) {
            $new['uses'] = $this->formatUses($new, $old);
        }

        $new['where'] = array_merge(Arr::get($old, 'where', []), Arr::get($new, 'where', []));

        if (isset($old['as'])) {
            $new['as'] = trim($old['as'].'.'.Arr::get($new, 'as', ''), '.');
        }

        return array_merge_recursive(array_except($old, ['namespace', 'prefix', 'where', 'as']), $new);
    }
1011933
protected static function formatGroupPrefix($new, $old)
    {
        $oldPrefix = $old['prefix'] ?? null;

        if (isset($new['prefix'])) {
            return \trim($oldPrefix, '/').'/'.\trim($new['prefix'], '/');
        }

        return $oldPrefix;
    }
125920
protected static function formatUsesPrefix($new, $old)
    {
        if (isset($new['namespace']) && isset($old['namespace'])) {
            return trim(array_get($old, 'namespace'), '\\') . '\\' . trim($new['namespace'], '\\');
        } elseif (isset($new['namespace'])) {
            return trim($new['namespace'], '\\');
        }
        
        return array_get($old, 'namespace');
    }
911206
public function changeKeys($original, $new, &$array)
    {
        foreach ($array as $k => $v) {
            $res[$k === $original ? $new : $k] = $v;
        }
        return $res;
    }
1074002
public function appendToArray(array $array, $key, array $new)
    {
        $keys = array_keys($array);
        $index = array_search($key, $keys);
        $pos = false === $index ? count($array) : $index + 1;

        return array_merge(array_slice($array, 0, $pos), $new, array_slice($array, $pos));
    }
346622
public function mergeConditions( ConditionInterface $old, ConditionInterface $new ) {
		if ( $old instanceof UrlCondition && $new instanceof UrlCondition ) {
			return $old->concatenate( $new->getUrl(), $new->getUrlWhere() );
		}

		return $this->makeFromArrayOfConditions( [$old, $new] );
	}
1042424
protected function getForeignKeysMigrations($new = [], $old = [])
    {
        if (empty($new['tables'])) {
            return [];
        }
        $output = [];
        foreach ($new['tables'] as $tableId => $newTable) {
            if ($newTable['table']['table_name'] === $this->options['default_migration_table']) {
                continue;
            }
            $oldTable = $old['tables'][$tableId];

            if (!empty($oldTable['foreign_keys'])) {
                foreach ($oldTable['foreign_keys'] as $fkName => $fkData) {
                    if (!isset($newTable['foreign_keys'][$fkName])) {
                        $output[] = $this->getForeignKeyRemove($tableId, $fkName);
                    }
                }
            }
            if (!empty($newTable['foreign_keys'])) {
                foreach ($newTable['foreign_keys'] as $fkName => $fkData) {
                    if (!isset($oldTable['foreign_keys'][$fkName])) {
                        $output[] = $this->getForeignKeyCreate($tableId, $fkName);
                    }
                }
            }
        }

        return $output;
    }
485023
public function createUpdateQuery($old, $new, $prefix = "")
    {
        $update = [];

        foreach ($new as $key => $value) {
            if (is_array($old) && array_key_exists($key, $old)) {
                if (is_array($value) && strstr(key($value), '$') !== false) {
                    $update[key($value)][$prefix . $key] = $value[key($value)];
                } elseif (is_array($value) && is_array($old[$key])) {
                    if (!empty($old[$key])) {
                        $embeddedUpdate = array_merge_recursive($update, $this->createUpdateQuery($old[$key], $value, $prefix . $key . "."));
                        if (isset($embeddedUpdate['$unset']) && array_values($old[$key]) === $old[$key] && $value !== null && count(array_filter(array_keys($value), 'is_string')) == 0) {
                            $update['$set'][$prefix . $key] = array_values($value);
                        } else {
                            foreach ($embeddedUpdate as $updateOperator => $value) {
                                if (!isset($update[$updateOperator])) {
                                    $update[$updateOperator] = [];
                                }
                                $update[$updateOperator] += $value;
                            }
                        }
                    } elseif (!empty($value)) {
                        $update['$set'][$prefix . $key] = $value;
                    }
                } else {
                    if ($value !== null && $value !== $old[$key]) {
                        if ($value instanceof \MongoDB\BSON\UTCDateTime && $old[$key] instanceof \MongoDB\BSON\UTCDateTime) {
                            if (serialize($value) != serialize($old[$key])) {
                                $update['$set'][$prefix . $key] = $value;
                            }
                        } else {
                            $update['$set'][$prefix . $key] = $value;
                        }
                    } elseif ($value === null && $old[$key] !== null) {
                        $update['$unset'][$prefix . $key] = 1;
                    }
                }
            } else {
                if (is_array($value) && strstr(key($value), '$') === false) {
                    $embeddedQuery = $this->createUpdateQuery([], $value, $prefix . $key . ".");
                    if (count($embeddedQuery) == 1 && key($embeddedQuery) == '$set') {
                        $update['$set'][$prefix . $key] = $value;
                    } else {
                        $update = array_merge_recursive($update, $embeddedQuery);
                    }
                } elseif (is_array($value) && strstr(key($value), '$') !== false) {
                    $update[key($value)][$prefix . $key] = $value[key($value)];
                } else {
                    $update['$set'][$prefix . $key] = $value;
                }
            }

            unset($new[$key]);
            unset($old[$key]);
        }
        if (is_array($old)) {
            foreach (array_keys($old) as $key) {
                $update['$unset'][$prefix . $key] = 1;
            }
        }

        if (isset($update['$set']['_id'])) {
            unset($update['$set']['_id']);
        }

        foreach ($update as $modifier => $value) {
            if (empty($value)) {
                unset($update[$modifier]);
            }
        }

        return $update;
    }
1343980
public static function merge($new, $old)
    {
        if (isset($new['domain'])) {
            unset($old['domain']);
        }

        $new = array_merge(static::formatAs($new, $old), [
            'namespace' => static::formatNamespace($new, $old),
            'prefix' => static::formatPrefix($new, $old),
            'where' => static::formatWhere($new, $old),
        ]);

        return array_merge_recursive(Arr::except(
            $old, ['namespace', 'prefix', 'where', 'as']
        ), $new);
    }
555175
function changekey(array &$var,$old,$new) {
		$keys=array_keys($var);
		$vals=array_values($var);
		$keys[array_search($old,$keys)]=$new;
		$var=array_combine($keys,$vals);
	}
1060678
public function recursivelyFindAndReplaceExecutableCode($old)
    {
        if ($this->isArray($old)) {
            return collect($old)->map(function ($item) {
                return $this->recursivelyFindAndReplaceExecutableCode($item);
            });
        }

        $new = $this->replaceContents($old);

        if ($new !== $old) {
            $this->replaced++;
        }

        return $new;
    }
1115646
public static function renameKey(array &$arr, $oldKey, $newKey): void
    {
        $offset = self::searchKey($arr, $oldKey);
        if ($offset !== null) {
            $keys = \array_keys($arr);
            $keys[$offset] = $newKey;
            $arr = \array_combine($keys, $arr);
        }
    }