public static function removeValue(array $config, string $configPath): array
    {
        if (!is_string($configPath) || $configPath === '') {
            throw new InvalidArgumentException('Path must be not be empty string', 1496759385);
        }
        // Extract parts of the path
        $path = str_getcsv($configPath, '.');
        $pathDepth = count($path);
        $currentDepth = 0;
        $pointer = &$config;
        // Find path in given array
        foreach ($path as $segment) {
            $currentDepth++;
            // Fail if the part is empty
            if ($segment === '') {
                throw new InvalidArgumentException('Invalid path segment specified', 1496759389);
            }
            if (!array_key_exists($segment, $pointer)) {
                throw new PathDoesNotExistException(sprintf('Path "%s" does not exist in array (tried removing)', $configPath), 1496759405);
            }
            if ($currentDepth === $pathDepth) {
                unset($pointer[$segment]);
            } else {
                $pointer = &$pointer[$segment];
            }
        }

        return $config;
    }
public static function removeValue(array $config, string $configPath): array
    {
        if (!is_string($configPath) || $configPath === '') {
            throw new InvalidArgumentException('Path must be not be empty string', 1496759385);
        }
        // Extract parts of the path
        $path = str_getcsv($configPath, '.');
        $pathDepth = count($path);
        $currentDepth = 0;
        $pointer = &$config;
        // Find path in given array
        foreach ($path as $segment) {
            $currentDepth++;
            // Fail if the part is empty
            if ($segment === '') {
                throw new InvalidArgumentException('Invalid path segment specified', 1496759389);
            }
            if (!array_key_exists($segment, $pointer)) {
                throw new PathDoesNotExistException(sprintf('Path "%s" does not exist in array (tried removing)', $configPath), 1496759405);
            }
            if ($currentDepth === $pathDepth) {
                unset($pointer[$segment]);
            } else {
                $pointer = &$pointer[$segment];
            }
        }

        return $config;
    }
public static function removeValue ( array $ config , string $ configPath ) : array { if ( ! is_string ( $ configPath ) || $ configPath === '' ) { throw new InvalidArgumentException ( 'Path must be not be empty string' , 1496759385 ) ; } // Extract parts of the path $ path = str_getcsv ( $ configPath , '.' ) ; $ pathDepth = count ( $ path ) ; $ currentDepth = 0 ; $ pointer = & $ config ; // Find path in given array foreach ( $ path as $ segment ) { $ currentDepth ++ ; // Fail if the part is empty if ( $ segment === '' ) { throw new InvalidArgumentException ( 'Invalid path segment specified' , 1496759389 ) ; } if ( ! array_key_exists ( $ segment , $ pointer ) ) { throw new PathDoesNotExistException ( sprintf ( 'Path "%s" does not exist in array (tried removing)' , $ configPath ) , 1496759405 ) ; } if ( $ currentDepth === $ pathDepth ) { unset ( $ pointer [ $ segment ] ) ; } else { $ pointer = & $ pointer [ $ segment ] ; } } return $ config ; }
Removing a path of an array

Inspired by \TYPO3\CMS\Core\Utility\ArrayUtility

@param array $config
@param string $configPath Path separated by "."
@throws InvalidArgumentException
@return array
Removing a path of an array