AbstractRepository::merge

Merge new array of data into the data storage.

@param array $data New array of data.

@return array The old array of data storage.
979443
public function merge(array $data)
    {
        $oldStorage = $this->storage;
        $this->storage = array_merge($this->storage, $data);

        return $oldStorage;
    }
1337143
public static function mergeOverlappingRanges(array $data)
    {
        $result = [];
        $ranges = [];
        foreach ($data as $key => $value) {
            $value = is_array($value)
                ? static::mergeOverlappingRanges($value)
                : (is_string($value) ? TimeRange::fromString($value) : $value);

            if ($value instanceof TimeRange) {
                $newRanges = [];
                foreach ($ranges as $range) {
                    if ($value->format() === $range->format()) {
                        continue 2;
                    }

                    if ($value->overlaps($range) || $range->overlaps($value)) {
                        $value = TimeRange::fromList([$value, $range]);

                        continue;
                    }

                    $newRanges[] = $range;
                }

                $newRanges[] = $value;
                $ranges = $newRanges;

                continue;
            }

            $result[$key] = $value;
        }

        foreach ($ranges as $range) {
            $result[] = $range;
        }

        return $result;
    }
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;
    }
1050750
public function merge(Config $config)
    {
        $this->data = array_replace_recursive(
            $this->data,
            $config->toArray()
        );

        return $this;
    }
436671
public function add(array $data)
    {
        $defaults = array(
            "description" => null,
            "price"       => null,
            "discount"    => null,
            "qty"         => 1,
            "unit"        => null
        );

        $merged = array_merge($defaults, $data);

        $line = $this->create($this->quotationHandle);

        if( isset($merged['product']) )
        {
            $this->product($line, $merged['product']);
            unset( $merged['product'] );
        }

        foreach( $merged as $name => $value )
        {
            if( is_null($value) )
                continue;

            switch($name)
            {
                case 'description':
                    $this->description($line, $value);
                    break;
                case 'price':
                    $this->price($line, $value);
                    break;
                case 'discount':
                    $this->discount($line, $value);
                    break;
                case 'qty':
                    $this->qty($line, $value);
                    break;
                case 'unit':
                    $this->unit($line, $value);
                    break;
            }
        }
    }
362823
protected function mergeConfigs(array $old, array $new) : array
    {
      foreach ($new as $key => $val) {
        if (!array_key_exists($key, $old) || !is_array($old[$key]) || !is_array($val)) {
          $old[$key] = $val;
          continue;
        }

        if (is_int($key)) {
          $old[] = $val;
          continue;
        }

        $old[$key] = $this->mergeConfigs($old[$key], $val);
      }

      return $old;
    }
1163474
public static function merge($array1, $array2)
	{
		$result = [];
		for ($i = 0; $i < func_num_args(); $i++) {
			$result = parent::merge($result, static::asArray(func_get_arg($i)));
		}

		return $result;
	}
1282708
public function merge(array $data)
    {
        $this->isMergingWidgetData = true;

        $data = $this->setCoreData($data);

        $this->mergePropertyData($data);

        $this->isMergingWidgetData = false;

        return $this;
    }
1286825
protected function mergeData($data, $index, $merge, $numericKeys)
    {
        if ($numericKeys) {
            return $this->removeMissingValues(array_merge(
                array_merge(array_slice($data, 0, $index, true), $merge),
                $this->filter(array_values(array_slice($data, $index + 1, null, true)))
            ));
        }

        return $this->removeMissingValues(array_slice($data, 0, $index, true) +
                $merge +
                $this->filter(array_slice($data, $index + 1, null, true)));
    }
330642
public static function merge(): array
    {
        $args = func_get_args();
        $array = array_shift($args);

        while (! empty($args)) {
            $next = array_shift($args);

            foreach ($next as $key => $value) {
                if (is_int($key)) {
                    if (isset($array[$key])) {
                        $array[] = $value;
                    } else {
                        $array[$key] = $value;
                    }
                } elseif (is_array($value) && isset($array[$key]) && is_array($array[$key])) {
                    $array[$key] = static::merge($array[$key], $value);
                } else {
                    $array[$key] = $value;
                }
            }
        }

        return $array;
    }
405321
protected function mergeData(array $a, array $b)
    {
        if (isset($b['services']) === false) {
            return $b + $a;
        }

        return parent::mergeData($a, $b);
    }
285280
protected function mergePresets(array $data)
    {
        if (isset($data['attachable_objects'])) {
            $data['attachable_objects'] = $this->mergePresetAttachableObjects($data['attachable_objects']);
        }

        if (isset($data['default_attachable_objects'])) {
            $data['attachable_objects'] = $this->mergePresetAttachableObjects($data['default_attachable_objects']);
        }

        if (isset($data['preset'])) {
            $data = $this->mergePresetWidget($data);
        }

        return $data;
    }
1353034
public static function recursiveMerge(...$arrays)
    {
        $merged = array ();
        foreach($arrays as $array)
        {
            if (!is_array($array))
            {
                continue;
            }
            foreach ( $array as $key => $value )
            {
                if (is_string ( $key ))
                {
                    if (is_array ( $value ) && isset($merged[$key]) && is_array ( $merged [$key] ))
                    {
                        $merged [$key] = static::recursiveMerge ( $merged [$key], $value );
                    }
                    else
                    {
                        $merged [$key] = $value;
                    }
                }
                else
                {
                    $merged [] = $value;
                }
            }
        }
        return $merged;
    }
1374487
protected function fromArray($data)
    {
        if (empty($data)) {
            return $this;
        }

        $this->data = array_replace_recursive($this->data, $data);

        return $this;
    }
154175
public function merge($data)
	{
		foreach ($data as $key => $value) {
			$this->set($key, $value);
		}
	}
254268
public function merge(array $data, $append = false)
    {
        if ($append) {
            return $this->config = array_merge($this->config, $data);
        }
        return array_merge($this->config, $data);
    }
826051
public static function merge($currentArray, $newArray)
    {
        $mergeIdentifier = '__APPEND__';

        if (is_array($currentArray) && !is_array($newArray)) {
            return $currentArray;
        } else if (!is_array($currentArray) && is_array($newArray)) {
            return $newArray;
        } else if ((!is_array($currentArray) || empty($currentArray)) && (!is_array($newArray) || empty($newArray))) {
            return array();
        }

        foreach ($newArray as $newName => $newValue) {

            if (is_array($newValue) && array_key_exists($newName, $currentArray) && is_array($currentArray[$newName])) {

                // check __APPEND__ identifier
                $appendKey = array_search($mergeIdentifier, $newValue, true);
                if ($appendKey !== false) {
                    unset($newValue[$appendKey]);
                    $newValue = array_merge($currentArray[$newName], $newValue);
                } else if (!static::isSingleArray($newValue) || !static::isSingleArray($currentArray[$newName])) {
                    $newValue = static::merge($currentArray[$newName], $newValue);
                }

            }

            //check if exists __APPEND__ identifier and remove its
            if (!isset($currentArray[$newName]) && is_array($newValue)) {
                $newValue = static::unsetInArrayByValue($mergeIdentifier, $newValue);
            }

            $currentArray[$newName] = $newValue;
        }

        return $currentArray;
    }