Merges two or more arrays into one recursively.

@return array
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;
    }
1059212
private function _merge(array $data) : array
    {
        $values = $this->getValues();
        $values = array_merge($values, $data);
        return $values;
    }
620017
public static function merge_data_recursive($a, $b)
    {
        $args = func_get_args();
        $t = $args[0];
        $array = is_array($t);

        foreach ($args as $k => $a) {
            $args[$k] = self::ar($a, null, true);
        }

        $args = call_user_func_array('array_merge_recursive', $args);
        
        if (!$array) {
            $args = self::sc($args, null, true);
        }

        return $args;
    }
803476
public static function merge(array ...$arrays): array
    {
        $res = array_shift($arrays);
        while (!empty($arrays)) {
            foreach (array_shift($arrays) as $key => $value) {
                if (is_int($key)) {
                    if (array_key_exists($key, $res)) {
                        $res[] = $value;
                    } else {
                        $res[$key] = $value;
                    }
                } elseif (
                    is_array($value)
                    && isset($res[$key])
                    && is_array($res[$key])
                ) {
                    $res[$key] = static::merge($res[$key], $value);
                } else {
                    $res[$key] = $value;
                }
            }
        }
        return $res;
    }
29506
public static function array_merge_recursive()
  {
    if ( func_num_args() < 2 ){
      trigger_error(__METHOD__ .' needs two or more array arguments', E_USER_WARNING);
    }
    
    $arrays = func_get_args();
    $merged = [];
    
    while($arrays){
      $array = array_shift($arrays);
      if ( !is_array($array) ){
        trigger_error(__METHOD__ .' encountered a non array argument', E_USER_WARNING);
      }
      
      if ( !$array ){
        continue;
      }
      
      foreach($array as $key => $value){
        if ( is_string($key) ){
          if ( is_array($value) && array_key_exists($key, $merged) && is_array($merged[$key]) ){
            $merged[$key] = call_user_func([__NAMESPACE__ . '\\Arrayhelper', __METHOD__], $merged[$key], $value);
          }
          else {
            $merged[$key] = $value;
          }
        }
        else {
          $merged[] = $value;
        }
      }
    }
    
    return $merged;
  }
1118068
protected function merge_arrays() {
        $arrays = func_get_args();
        $narrays = count($arrays);

        // check arguments
        // comment out if more performance is necessary (in this case the foreach loop will trigger a warning if the argument is not an array)
        for ($i = 0; $i < $narrays; $i ++) {
            if (!is_array($arrays[$i])) {
                // also array_merge_recursive returns nothing in this case
                trigger_error('Argument #' . ($i+1) . ' is not an array - trying to merge array with scalar! Returning false!', E_USER_WARNING);
                return false;
            }
        }

        // the first array is in the output set in every case
        $ret = $arrays[0];

        // merege $ret with the remaining arrays
        for ($i = 1; $i < $narrays; $i ++) {
            foreach ($arrays[$i] as $key => $value) {
                if (is_array($value) && isset($ret[$key])) {
                    // if $ret[$key] is not an array you try to merge an scalar value with an array - the result is not defined (incompatible arrays)
                    // in this case the call will trigger an E_USER_WARNING and the $ret[$key] will be false.
                    $ret[$key] = $this->merge_arrays($ret[$key], $value);
                } else {
                    $ret[$key] = $value;
                }
            }
        }

        return $ret;
    }
232236
protected function merge($a, $b)
    {
        if (!is_array($a)) {
            if (!is_array($b)) return [];
            return $b;
        }

        if (!is_array($b)) return $a;

        foreach($b as $k => $v) {
            if (!isset($a[$k])) {
                $a[$k] = $v;
                continue;
            }
            if (!is_array($v)) {
                if (!is_array($a[$k])) {
                    $a[$k] = $v;
                    continue;
                }
                $a[$k] = array_merge($a[$k], [$v]);
                foreach(array_keys($a[$k]) as $kk) {
                    if (is_numeric($kk)) {
                        $a[$k] = array_unique($a[$k]);
                        break;
                    }
                }
                continue;
            }
            $a[$k] = array_merge($a[$k], $b[$k]);
            foreach(array_keys($a[$k]) as $kk) {
                if (is_numeric($kk)) {
                    $a[$k] = array_unique($a[$k]);
                    break;
                }
            }
        }

        return $a;
    }
1202245
public function allArray() {
        $r=array();
        foreach($this->items as $v) {
            $r=array_merge($r,$v->allError());
            $r=array_merge($r,$v->allWarning());
            $r=array_merge($r,$v->allInfo());
            $r=array_merge($r,$v->allSuccess());
        }
        return $r;
    }
199348
protected function merge()
    {
        if (null === $this->merge) {
            $this->merge = new MergeBuilder($this);
        }

        return $this->merge;
    }
500060
public static function merge(array $array1, array $array2, $deep = false)
    {
        // Normal array merge
        if (!$deep) {
            return array_merge($array1, $array2);
        }

        // Perform a deep merge
        $merged = $array1;

        foreach ($array2 as $key => $value) {
            if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
                $merged[$key] = static::merge($merged[$key], $value, $deep);
            } else if (is_numeric($key)) {
                if (!in_array($value, $merged)) {
                    $merged[] = $value;
                }
            } else {
                $merged[$key] = $value;
            }
        }

        return $merged;
    }
92474
public static function merge($array1, $array2, $recursive = false)
    {
        if (!self::isValid($array1) ||
            !self::isValid($array2)) {
            return false;
        }

        if ($recursive) {
            return array_merge_recursive($array1, $array2);
        } else {
            return array_merge($array1, $array2);
        }
    }
696895
private function mergeRules()
    {
        $rules = static::$rules;
        $output = array();

        if (empty ($rules))
        {
            return $output;
        }

        if ($this->exists)
        {
            $merged = (isset($rules['update'])) ? array_merge_recursive($rules['save'], $rules['update']) : $rules['save'];
        } else
        {
            $merged = (isset($rules['create'])) ? array_merge_recursive($rules['save'], $rules['create']) : $rules['save'];
        }

        foreach ($merged as $field => $rules)
        {
            if (is_array($rules))
            {
                $output[$field] = implode("|", $rules);
            } else
            {
                $output[$field] = $rules;
            }
        }

        return $output;
    }
937268
public static function merge2(...$args): array
    {
        /** @var array[] $args */
        $res = array_shift($args);

        while (!empty($args)) {
            /** @var array $next */
            $next = array_shift($args);

            foreach ($next as $k => $v) {
                if (\is_int($k)) {
                    if (isset($res[$k])) {
                        $res[] = $v;
                    } else {
                        $res[$k] = $v;
                    }
                } elseif (\is_array($v) && isset($res[$k]) && \is_array($res[$k])) {
                    $res[$k] = self::merge2($res[$k], $v);
                } else {
                    $res[$k] = $v;
                }
            }
        }

        return $res;
    }
1056279
public function toArray()
    {

        $attributes = [];

        foreach ($this->attributes as $name => $value) {
            $attributes[$name] = $this->getOriginalAttribute($name);
        }

        foreach ($this->appends as $name) {
            $attributes[$name] = $this->getAppendsAttribute($name);
        }

        return $attributes;
    }
795432
public function merge()
    {
        $this->xmlParsed .= str_replace(array_keys($this->vars), array_values($this->vars), $this->xml);
        if ($this->hasChildren()) {
            foreach ($this->children as $child) {
                $this->xmlParsed = str_replace($child->xml, ($child->xmlParsed=="")?$child->merge():$child->xmlParsed, $this->xmlParsed);
                $child->xmlParsed = '';
                //Store all image names used in child segments in current segment array
                foreach ($child->manif_vars as $file) {
                    $this->manif_vars[] = $file;
                }

                $child->manif_vars = array();
            }
        }
        $reg = "/\[!--\sBEGIN\s$this->name\s--\](.*)\[!--\sEND\s$this->name\s--\]/smU";
        $this->xmlParsed = preg_replace($reg, '$1', $this->xmlParsed);
        $this->file->open($this->odf->getTmpfile());
        foreach ($this->images as $imageKey => $imageValue) {
            if ($this->file->getFromName('Pictures/' . $imageValue) === false) {
                $this->file->addFile($imageKey, 'Pictures/' . $imageValue);
            }
        }

        $this->file->close();
        return $this->xmlParsed;
    }
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;
    }
1112407
public function toArray()
	{
		$array = array ();
		for ($i=$this->interval->getStart(); $i<$this->interval->getEnd(); $i++)
		{
			$value = $this->getValue ($i);
			$array [$i] = $value;
		}
		return $array;
	}