public static function setValue(array $array, string $configPath, $value): array
    {
        if (!is_string($configPath) || $configPath === '') {
            throw new InvalidArgumentException('Path must be not be empty string', 1496472912);
        }
        // Extract parts of the configPath
        $path = str_getcsv($configPath, '.');
        // Point to the root of the array
        $pointer = &$array;
        // Find configPath in given array
        foreach ($path as $segment) {
            // Fail if the part is empty
            if ($segment === '') {
                throw new InvalidArgumentException('Invalid path segment specified', 1496472917);
            }
            // Create cell if it doesn't exist
            if (!array_key_exists($segment, $pointer)) {
                $pointer[$segment] = [];
            }
            // Set pointer to new cell
            $pointer = &$pointer[$segment];
        }
        // Set value of target cell
        $pointer = $value;

        return $array;
    }
public static function setValue(array $array, string $configPath, $value): array
    {
        if (!is_string($configPath) || $configPath === '') {
            throw new InvalidArgumentException('Path must be not be empty string', 1496472912);
        }
        // Extract parts of the configPath
        $path = str_getcsv($configPath, '.');
        // Point to the root of the array
        $pointer = &$array;
        // Find configPath in given array
        foreach ($path as $segment) {
            // Fail if the part is empty
            if ($segment === '') {
                throw new InvalidArgumentException('Invalid path segment specified', 1496472917);
            }
            // Create cell if it doesn't exist
            if (!array_key_exists($segment, $pointer)) {
                $pointer[$segment] = [];
            }
            // Set pointer to new cell
            $pointer = &$pointer[$segment];
        }
        // Set value of target cell
        $pointer = $value;

        return $array;
    }
public static function setValue ( array $ array , string $ configPath , $ value ) : array { if ( ! is_string ( $ configPath ) || $ configPath === '' ) { throw new InvalidArgumentException ( 'Path must be not be empty string' , 1496472912 ) ; } // Extract parts of the configPath $ path = str_getcsv ( $ configPath , '.' ) ; // Point to the root of the array $ pointer = & $ array ; // Find configPath in given array foreach ( $ path as $ segment ) { // Fail if the part is empty if ( $ segment === '' ) { throw new InvalidArgumentException ( 'Invalid path segment specified' , 1496472917 ) ; } // Create cell if it doesn't exist if ( ! array_key_exists ( $ segment , $ pointer ) ) { $ pointer [ $ segment ] = [ ] ; } // Set pointer to new cell $ pointer = & $ pointer [ $ segment ] ; } // Set value of target cell $ pointer = $ value ; return $ array ; }
Setting a value to an array in a given path

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

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