public static function getValue(array $config, string $configPath, $default = null)
    {
        if ($configPath === '') {
            throw new InvalidArgumentException('Path must be not be empty string', 1496758719);
        }
        $path = str_getcsv($configPath, '.');
        // Loop through each part and extract its value
        $value = $config;
        foreach ($path as $segment) {
            if (array_key_exists($segment, $value)) {
                // Replace current value with child
                $value = $value[$segment];
            } else {
                if (\count(\func_get_args()) !== 2) {
                    return $default;
                }
                // Fail if key does not exist and no default value is provided
                throw new PathDoesNotExistException(sprintf('Path "%s" does not exist in array (tried reading)', $configPath), 1496758722);
            }
        }

        return $value;
    }
public static function getValue(array $config, string $configPath, $default = null)
    {
        if ($configPath === '') {
            throw new InvalidArgumentException('Path must be not be empty string', 1496758719);
        }
        $path = str_getcsv($configPath, '.');
        // Loop through each part and extract its value
        $value = $config;
        foreach ($path as $segment) {
            if (array_key_exists($segment, $value)) {
                // Replace current value with child
                $value = $value[$segment];
            } else {
                if (\count(\func_get_args()) !== 2) {
                    return $default;
                }
                // Fail if key does not exist and no default value is provided
                throw new PathDoesNotExistException(sprintf('Path "%s" does not exist in array (tried reading)', $configPath), 1496758722);
            }
        }

        return $value;
    }
public static function getValue ( array $ config , string $ configPath , $ default = null ) { if ( $ configPath === '' ) { throw new InvalidArgumentException ( 'Path must be not be empty string' , 1496758719 ) ; } $ path = str_getcsv ( $ configPath , '.' ) ; // Loop through each part and extract its value $ value = $ config ; foreach ( $ path as $ segment ) { if ( array_key_exists ( $ segment , $ value ) ) { // Replace current value with child $ value = $ value [ $ segment ] ; } else { if ( \ count ( \ func_get_args ( ) ) !== 2 ) { return $ default ; } // Fail if key does not exist and no default value is provided throw new PathDoesNotExistException ( sprintf ( 'Path "%s" does not exist in array (tried reading)' , $ configPath ) , 1496758722 ) ; } } return $ value ; }
Getting a value to an array in a given path

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

@param array $config
@param string $configPath Path separated by "."
@param mixed $default
@throws InvalidArgumentException
@throws PathDoesNotExistException
@return mixed
Getting a value to an array in a given path