public static function setValueByPath($subject, $path, $value)
    {
        if (!is_array($subject) && !($subject instanceof \ArrayAccess)) {
            throw new \InvalidArgumentException('setValueByPath() expects $subject to be array or an object implementing \ArrayAccess, "' . (is_object($subject) ? get_class($subject) : gettype($subject)) . '" given.', 1306424308);
        }
        if (is_string($path)) {
            $path = explode('.', $path);
        } elseif (!is_array($path)) {
            throw new \InvalidArgumentException('setValueByPath() expects $path to be string or array, "' . gettype($path) . '" given.', 1305111499);
        }
        $key = array_shift($path);
        if (count($path) === 0) {
            $subject[$key] = $value;
        } else {
            if (!isset($subject[$key]) || !is_array($subject[$key])) {
                $subject[$key] = [];
            }
            $subject[$key] = self::setValueByPath($subject[$key], $path, $value);
        }
        return $subject;
    }
public static function setValueByPath($subject, $path, $value)
    {
        if (!is_array($subject) && !($subject instanceof \ArrayAccess)) {
            throw new \InvalidArgumentException('setValueByPath() expects $subject to be array or an object implementing \ArrayAccess, "' . (is_object($subject) ? get_class($subject) : gettype($subject)) . '" given.', 1306424308);
        }
        if (is_string($path)) {
            $path = explode('.', $path);
        } elseif (!is_array($path)) {
            throw new \InvalidArgumentException('setValueByPath() expects $path to be string or array, "' . gettype($path) . '" given.', 1305111499);
        }
        $key = array_shift($path);
        if (count($path) === 0) {
            $subject[$key] = $value;
        } else {
            if (!isset($subject[$key]) || !is_array($subject[$key])) {
                $subject[$key] = [];
            }
            $subject[$key] = self::setValueByPath($subject[$key], $path, $value);
        }
        return $subject;
    }
public static function setValueByPath ( $ subject , $ path , $ value ) { if ( ! is_array ( $ subject ) && ! ( $ subject instanceof \ ArrayAccess ) ) { throw new \ InvalidArgumentException ( 'setValueByPath() expects $subject to be array or an object implementing \ArrayAccess, "' . ( is_object ( $ subject ) ? get_class ( $ subject ) : gettype ( $ subject ) ) . '" given.' , 1306424308 ) ; } if ( is_string ( $ path ) ) { $ path = explode ( '.' , $ path ) ; } elseif ( ! is_array ( $ path ) ) { throw new \ InvalidArgumentException ( 'setValueByPath() expects $path to be string or array, "' . gettype ( $ path ) . '" given.' , 1305111499 ) ; } $ key = array_shift ( $ path ) ; if ( count ( $ path ) === 0 ) { $ subject [ $ key ] = $ value ; } else { if ( ! isset ( $ subject [ $ key ] ) || ! is_array ( $ subject [ $ key ] ) ) { $ subject [ $ key ] = [ ] ; } $ subject [ $ key ] = self :: setValueByPath ( $ subject [ $ key ] , $ path , $ value ) ; } return $ subject ; }
Sets the given value in a nested array or object by following the specified path.

@param array|\ArrayAccess $subject The array or ArrayAccess instance to work on
@param array|string $path The path to follow. Either a simple array of keys or a string in the format 'foo.bar.baz'
@param mixed $value The value to set
@return array|\ArrayAccess The modified array or object
@throws \InvalidArgumentException
Sets the given value in a nested array or object by following the specified path .