Apply (add) $new array to collection or replace it completely (when $purge is true).

@param array $new
@param bool  $purge [optional]
768501
protected function apply(array $new, $purge = false)
    {
        $old = $this->collection;

        // Delete old values
        // Note: make sure not to overwrite / detach original object to make changes be globally effective
        if ($purge) {
            foreach ($old as $key => $value) {
                unset($old[$key]);
            }
        }

        // Set new values
        foreach ($new as $key => $value) {
            $old[$key] = $value;
        }
    }
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);
    }
1217052
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']);

		return array_merge_recursive(array_except($old, array('namespace', 'prefix')), $new);
	}
137593
protected function mergeExisting($new, $existing)
    {
        foreach ($new as $aliasName => &$newAlias) {
            // If the alias already exists, recursively replace existing
            // settings with new ones.
            if (isset($existing[$aliasName])) {
                $newAlias = array_replace_recursive($existing[$aliasName], $newAlias);
            }
        }

        return $new;
    }
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);
	}
94402
public function move(string $old, string $new){
    if (
      !empty($old) &&
      !empty($new) &&
      ($old = $this->checkFilePath($old)) &&
      ftp_rename($this->cn, $old, $new)
    ){
      return true;
    }
    return false;
  }
482421
static function replaceHeaders(array $newHeaders): bool
    {
        if (!headers_sent()) {
            header_remove();

            foreach ($newHeaders as $header) {
                header($header);
            }

            return true;
        }

        return false;
    }
775007
public static function registerCustomView(string $old, string $new): void
    {
        if (Str::contains($old, self::NAMESPACE_SEPARATOR) && Str::contains($new, self::NAMESPACE_SEPARATOR)) {
            self::$replacements[$old] = $new;
        } else {
            throw new InvalidArgumentException();
        }
    }
1009606
public static function replace_key(array $array, $oldKey, $newKey) : array
  {
    $newArray = array();

    foreach ($array as $key => $value) {
      if ($key == $oldKey) {
        $newArray = array_merge($newArray, [$newKey => $value]);
      } else {
        $newArray = array_merge($newArray, [$key => $value]);
      }
    }

    return $newArray;
  }
981620
protected function renameResult(array &$result, $old, $new)
    {

        // Check to see if the old item is there
        if (isset($result[$old])) {
            $result[$new] = $result[$old];
            unset($result[$old]);
        }
    }
34626
protected function auditUpdatedAttributes(array &$old, array &$new)
    {
        foreach ($this->getDirty() as $attribute => $value) {
            if ($this->isAttributeAuditable($attribute)) {
                $old[$attribute] = array_get($this->original, $attribute);
                $new[$attribute] = array_get($this->attributes, $attribute);
            }
        }
    }
728727
public function update($newValues)
    {
        foreach ($newValues as $key => $value) {
            $this->offsetSet($key, $value);
        }

        return $this;
    }
529573
public function mergeQueryAttribute( $old, $new ) {
		if ( $new === null ) {
			return $old;
		}

		if ( $old === null ) {
			return $new;
		}

		return function ( $query_vars ) use ( $old, $new ) {
			return call_user_func( $new, call_user_func( $old, $query_vars ) );
		};
	}
1299981
private static function addFilters(array &$current_filters, array $new_filters)
    {
        foreach($new_filters as $verb=>$new_filter) {
            foreach ($new_filter as $f=>$v) {
                if(count($current_filters) == 0) {
                    $current_filters = [$verb => [$f=>$v]];
                }
                else {
                    if (!isset($current_filters['bool']['must'])) {
                        // Wrap the previous filter in a boolean (must) filter
                        $current_filters = ['bool' => ['must' => [$current_filters]]];
                    }
                    $current_filters['bool']['must'][] = [$verb => [$f => $v]];
                }
            }
        }
    }
772774
public function update($old, $new): bool
    {
        if ($this->hasNot($old)) {
            return false;
        }

        $this->set($old, $new);

        return true;
    }
783118
public function merge($newValues, $override = true)
    {
        foreach ($newValues as $key => $value) {
            // If the key doesn't exist yet,
            // we can simply set it.
            if (!array_key_exists($key, $this)) {
                $this[$key] = $value;
                continue;
            }

            // We already know this value exists
            // so if we're in conservative mode
            // we can skip this key
            if ($override === false) {
                continue;
            }

            // Merge the values only if
            // both values are arrays
            if (is_array($this[$key]) && is_array($value)) {
                $this[$key] = array_replace_recursive($this[$key], $value);
            } else {
                $this[$key] = $value;
            }
        }
    }
1006521
public function rename($old, $new)
    {
        return ($this->isConnected() === true) ? ftp_rename($this->getConnection(), $old, $new) : false;
    }