Nest an array at another depth using the prefix

@param  string $prefix
@param  array  $array
@return array
176962
public function nestArray($prefix, $array)
    {
        $data = [];
        foreach($array as $key => $value) {
            array_set($data, $prefix.$key, $value);
        }
        return $data;
    }
331357
public function extractAll(array $array, int $depth = 1)
    {
        $depth--;
        $res = [];
        foreach ($array as $key => $object) {
            $res[$key] = $depth>0 ? $this->extractAll($object, $depth) : $this->extract($object);
        }

        return $res;
    }
678940
public static function CleanPrefixedkeyInAssocArray($array, $prefix = "\0*\0") {
        $cleanedArray = array("array");
        foreach ($array as $key => $value) {
            $keyCleaned = str_replace($prefix, "", $key);
            $cleanedArray["array"][$keyCleaned] = $value;
        }
        return $cleanedArray["array"];
    }
79110
public function arrayKeysSnakeRecursive($array)
    {
        $result = [];

        $array = arrayable($array) ? $array->toArray() : $array;

        array_walk($array, function ($value, $key) use (&$result) {
            $result[snake_case($key)] = arrayable($value) || is_array($value)
                ? $this->arrayKeysSnakeRecursive($value)
                : $value;
        });

        return coollect($result);
    }
828697
public static function aggregate($array, $specialKeys = self::SPECIALS_KEYS, $prefix = '')
    {
        $new = [];
        foreach ($array as $key => $value) {
            $newKey = (!empty($prefix)) ? $prefix . '.' . $key : $key;
            if (!in_array($key, $specialKeys, true) && !in_array($key, array_keys($specialKeys), true)) {
                if (is_a($value, "stdClass")) {
                    $value = (array) $value;
                }

                if (is_array($value)) {
                    $new += self::aggregate($value, $specialKeys, $newKey);
                } else {
                    $new[$newKey] = $value;
                }
            } else {
                if (array_key_exists($key, $specialKeys) && is_callable($specialKeys[$key])) {
                    $new = call_user_func($specialKeys[$key], $prefix, $key, $value, $new);
                }
            }
        }

        return $new;
    }
143429
protected function flatten($array)
    {
        return array_reduce($array, function ($result, $item) {
            if (! is_array($item)) {
                return array_merge($result, [$item]);
            }

            return array_merge($result, $this->flatten($item));
        }, []);
    }
1112302
public function resolveMessageArrayToMessageKeys(array $messages, $prefix="")
    {
        $flatArray = [];

        foreach ($messages as $key=>$message) {
            $this->resolveMessageToKeys($message, $key, function($qualifiedKey) use(&$flatArray)
                {
                    $flatArray[] = $qualifiedKey;
                }, $prefix);
        }

        return $flatArray;
    }
744761
public static function recurse( $array, $array1 ) {
		foreach ( $array1 as $key => $value ) {

			// Create new key in $array, if it is empty or not an array.
			if ( ! isset( $array[ $key ] ) || ( isset( $array[ $key ] ) && ! is_array( $array[ $key ] ) ) ) {
				$array[ $key ] = [];
			}

			// Overwrite the value in the base array.
			if ( is_array( $value ) ) {
				$value = self::recurse( $array[ $key ], $value );
			}
			$array[ $key ] = $value;
		}
		return $array;
	}
1295173
public function convertArrayToDotNotation(array $array)
    {
        $recursiveIterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($array));

        $newArray = [];

        foreach ($recursiveIterator as $leafValue) {
            $keys = [];

            foreach (range(0, $recursiveIterator->getDepth()) as $depth) {
                $keys[] = $recursiveIterator->getSubIterator($depth)->key();
            }

            $newArray[implode('.', $keys)] = $leafValue;
        }

        return $newArray;
    }
1096748
public function getPrefixString($array, $prefix)
    {
        $items = array();

        if(!empty($array)){
            foreach($array as $item){
                preg_match('/'.$prefix.'(.*)/', $item, $results);
                if(isset($results[1])){
                    $items[] = $results[1];
                }
            }
        }

        return $items;
    }
229776
public static function unDot(array $array, $depth = INF): array
    {
        $results = [];

        foreach ($array as $key => $value) {
            if (count($dottedKeys = explode('.', (string) $key, 2)) > 1) {
                $results[$dottedKeys[0]][$dottedKeys[1]] = $value;
            } else {
                $results[$key] = $value;
            }
        }

        foreach ($results as $key => $value) {
            if (is_array($value) && ! empty($value) && $depth > 1) {
                $results[$key] = static::unDot($value, $depth - 1);
            }
        }

        return $results;
    }
1309955
protected function resolveLastDecendant($array, array $keys): ?Fluent
    {
        $isLastDescendant = function ($array, $segment) {
            return ! \is_array($array->childs) || ! isset($array->childs[$segment]);
        };

        // To retrieve the array item using dot syntax, we'll iterate through
        // each segment in the key and look for that value. If it exists,
        // we will return it, otherwise we will set the depth of the array
        // and look for the next segment.
        foreach ($keys as $segment) {
            if ($isLastDescendant($array, $segment)) {
                return $array;
            }

            $array = $array->childs[$segment];
        }

        return $array;
    }
539679
public static function flatten($array, $depth = INF)
    {
        $result = [];

        foreach ($array as $item) {
            $item = $item instanceof Collection ? $item->all() : $item;

            if (is_array($item)) {
                if ($depth === 1) {
                    $result = array_merge($result, $item);
                    continue;
                }

                $result = array_merge($result, static::flatten($item, $depth - 1));
                continue;
            }

            $result[] = $item;
        }

        return $result;
    }
846564
public static function prefixArrayKeys($array, $prefix) {

        $prefixedArray = array();
        foreach ($array as $key => $value) {
            $prefixedArray [$prefix . $key] = $value;
        }

        return $prefixedArray;

    }
635398
protected function descendants(array $array, ?string $key = null)
    {
        if (\is_null($key)) {
            return $array;
        }

        $keys = \explode('.', $key);
        $first = \array_shift($keys);

        if (! isset($array[$first])) {
            return null;
        }

        return $this->resolveLastDecendant($array[$first], $keys);
    }
957775
private function prefixPaths (array $paths, string $prefix) : array
    {
        $result = [];

        foreach ($paths as $namespace => $path)
        {
            $result[$namespace] = "{$prefix}/" . trim($path, "/");
        }

        return $result;
    }
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;
    }