Merge two arrays by using blueprints.

@param  array $data1
@param  array $data2
@param  string $name         Optional
@param  string $separator    Optional
@return array
760780
public function mergeData(array $data1, array $data2, $name = null, $separator = '.')
    {
        $nested = $this->getNested($name, $separator);

        if (!\is_array($nested)) {
            $nested = [];
        }

        return $this->mergeArrays($data1, $data2, $nested);
    }
393578
public static function merge(
        string $list1,
        string $list2,
        bool $sort,
        string $separator,
        string $tag = ''
    ): string {
        $items1 = self::explode($separator, $list1);
        $items2 = self::explode($separator, $list2);
        if (count($items2) > 0) {
            foreach ($items2 as $item) {
                if (!in_array($item, $items1)) {
                    $items1[] = $item;
                }
            }
        }
        if ($sort) {
            sort($items1);
        }
        return implode($separator, $items1);
    }
1101103
public static function merge(array $source1, array $source2): array
    {
        $return = $source2;

        foreach ($source1 as $key => $value) {
            if ($value && is_array($value) && isset($source2[$key]) && is_array($source2[$key])) {
                $value = array_replace_recursive($source2[$key], $value);
            }
            $return[$key] = $value;
        }

        return $return;
    }
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;
    }
1117599
public static function mergeExtraArray($mergeDeep, $array1, $array2)
    {
        if ($mergeDeep) {
            return NestedArray::mergeDeep($array1, $array2);
        }

        return array_merge($array1, $array2);
    }
661279
public static String join(final Object[] arrays, final String separator) {

        return join(arrays, separator, ELEMENT_CONVERTER);

    }
1214976
public static function flattenArray(array $array, $separator = '_')
    {
        $resultArray = [];
        foreach ($array as $key => $val) {
            if (is_array($val)) {
                /* @noinspection AdditionOperationOnArraysInspection */
                $resultArray += self::prefixArray(self::flattenArray($val), $key, $separator);
            } else {
                $resultArray[$key] = $val;
            }
        }

        return $resultArray;
    }
609247
public static function dimensionizeArray($array, $separator = '.')
    {
        $dimArray = array();
        
        foreach ($array as $key => $value) {
            $key = trim($key, $separator);
            // checks if the key is a path
            if (strpos($key, $separator) !== false) {
                $parts = self::splitArrayPath($key, $separator);
                $firstPart = array_shift($parts);
                // recursively dimensionize the key
                $value = self::dimensionizeArray(array(implode($separator, $parts) => $value), $separator);
                
                if (isset($dimArray[$firstPart])) {
                    if (!is_array($dimArray[$firstPart])) {
                        // if $firstPart exists but is not an array, drops the value and use an array
                        $dimArray[$firstPart] = array();
                    }
                    // merge recursively both arrays
                    $dimArray[$firstPart] = self::mergeRecursive($dimArray[$firstPart], $value);
                } else {
                    $dimArray[$firstPart] = $value;
                }
                
            } else if (is_array($value)) {
                // dimensionize sub arrays
                $value = self::dimensionizeArray($value, $separator);
                if (isset($dimArray[$key])) {
                    $dimArray[$key] = self::mergeRecursive($dimArray[$key], $value);
                } else {
                    $dimArray[$key] = $value;
                }
            } else {
                $dimArray[$key] = $value;
            }
        }
        
        return $dimArray;
    }
465700
protected function flattenArray(array $array, $separator = null)
    {
        $flattened = array();

        if (is_null($separator)) {
            $separator = $this->separator;
        }

        foreach ($array as $key => $value) {
            if (is_array($value)) {
                $flattened = array_merge($flattened, $this->flattenArray($value, $key.$separator));
            } else {
                $flattened[trim($separator.$key, $this->separator)] = $value;
            }
        }

        return $flattened;
    }
1058629
public static function mergeRecursiveDistinct(array &$array1, array &$array2)
    {
        Deprecated::method(3.3, 'Use array_replace_recursive() or Arr::replaceRecursive() instead.');

        $merged = $array1;

        foreach ($array2 as $key => &$value) {
            // if $key = 'accept_file_types, don't merge.
            if ($key == 'accept_file_types') {
                $merged[$key] = $array2[$key];
                continue;
            }

            if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
                $merged[$key] = static::mergeRecursiveDistinct($merged[$key], $value);
            } else {
                $merged[$key] = $value;
            }
        }

        return $merged;
    }
98503
public static function concat(array $array, $separator = ' ')
    {
        $result = '';

        foreach ($array as $string) {
            if (is_string($string)) {
                $result .= $string;
            }
        }

        return $result;
    }
999994
public static function removeByPath(array &$data, $path, $separator = '.')
    {
        $nodes = static::getPathNodes($path, $separator);

        if (empty($nodes)) {
            return false;
        }

        $previous = null;
        $dataTmp = &$data;

        foreach ($nodes as $node) {
            if (is_array($dataTmp)) {
                if (empty($dataTmp[$node])) {
                    return false;
                }

                $previous = &$dataTmp;
                $dataTmp = &$dataTmp[$node];
            } else {
                return false;
            }
        }

        // Now, path go to the end, means we get latest node, set value to this node.
        unset($previous[$node]);

        return true;
    }
1115836
public function joinDefaults($name, $value, $separator = null)
    {
        if (\is_object($value)) {
            $value = (array) $value;
        }

        $old = $this->get($name, null, $separator);
        if ($old !== null) {
            $value = $this->getBlueprint()->mergeData($value, $old, $name, $separator);
        }

        $this->setNestedProperty($name, $value, $separator);

        return $this;
    }
827446
public static function recursiveMerge($array1, $array2) {

        if ($array1 instanceof AssociativeArray) {
            $array1 = $array1->toArray();
        }

        if ($array2 instanceof AssociativeArray) {
            $array2 = $array2->toArray();
        }

        if (ArrayUtils::isAssociative($array1) != ArrayUtils::isAssociative($array2)) {

            if (ArrayUtils::isAssociative($array1)) {
                $array1 = array($array1);
            } else {
                $array2 = array($array2);
            }
        }

        $combinedKeys = array_unique(array_merge(array_keys($array1), array_keys($array2)));

        $mergedArray = array();
        foreach ($combinedKeys as $key) {


            if (isset($array1[$key]) && isset($array2[$key])) {

                if ((is_array($array1[$key]) || $array1[$key] instanceof AssociativeArray) && (is_array($array2[$key]) || $array2[$key] instanceof AssociativeArray)) {
                    $mergedArray[$key] = ArrayUtils::recursiveMerge($array1[$key], $array2[$key]);
                } else {
                    $mergedArray[$key] = $array1[$key];
                }

            } else {
                $mergedArray[$key] = isset($array1[$key]) ? $array1[$key] : $array2[$key];
            }

        }


        return $mergedArray;
    }
1285936
public function createFromArray(array $data, $name = null)
    {
        $preloadOids = $itemList = array();
        $menu        = $this->_createFromArray($data, $name, $itemList, $preloadOids);

        if ($preloadOids && $this->aclProvider) {
            //preload all acls for menu items
            try {
                $this->aclProvider->findAcls($preloadOids);
            } catch(AclNotFoundException $e) {
            }
        }

        foreach ($itemList as $item) {
            $this->setContext($item[0], $item[1], $item[2]);
        }

        return $menu;
    }
758313
public function appendAttr(string $name, string $value, string $separator = ';')
    {

        if (isset($this->attr[$name])) {
            $this->attr[$name] .= ($separator . $value);
        } else {
            $this->attr[$name] = $value;
        }

        return $this;
    }
1232643
public function extract($name, $separator = '.')
    {
        $filter = $this->filter instanceof NullFilter ? null : $this->filter;

        return new static($this->get($name, [], 'raw', $separator), $filter);
    }