public static function setAndOverride(array &$array, $keyPath, $value)
    {
        self::checkKeyPathIsValidAndNonEmpty($keyPath);
        $keys = self::explodeKeys(strval($keyPath));
        $result = $array;
        $ptr = &$result;

        while ($keys !== array()) {
            $key = array_shift($keys);

            if (!array_key_exists($key, $ptr)) {
                $ptr[$key] = $keys === array() ? $value : array();
                $ptr = &$ptr[$key];
                continue;
            }
            $ptr = &$ptr[$key];
            if ($keys === array()) {
                $ptr = $value;
                break;
            }
            elseif (!is_array($ptr)) {
                $ptr = array();
            }
        }

        $array = $result;
    }
public static function setAndOverride(array &$array, $keyPath, $value)
    {
        self::checkKeyPathIsValidAndNonEmpty($keyPath);
        $keys = self::explodeKeys(strval($keyPath));
        $result = $array;
        $ptr = &$result;

        while ($keys !== array()) {
            $key = array_shift($keys);

            if (!array_key_exists($key, $ptr)) {
                $ptr[$key] = $keys === array() ? $value : array();
                $ptr = &$ptr[$key];
                continue;
            }
            $ptr = &$ptr[$key];
            if ($keys === array()) {
                $ptr = $value;
                break;
            }
            elseif (!is_array($ptr)) {
                $ptr = array();
            }
        }

        $array = $result;
    }
public static function setAndOverride ( array & $ array , $ keyPath , $ value ) { self :: checkKeyPathIsValidAndNonEmpty ( $ keyPath ) ; $ keys = self :: explodeKeys ( strval ( $ keyPath ) ) ; $ result = $ array ; $ ptr = & $ result ; while ( $ keys !== array ( ) ) { $ key = array_shift ( $ keys ) ; if ( ! array_key_exists ( $ key , $ ptr ) ) { $ ptr [ $ key ] = $ keys === array ( ) ? $ value : array ( ) ; $ ptr = & $ ptr [ $ key ] ; continue ; } $ ptr = & $ ptr [ $ key ] ; if ( $ keys === array ( ) ) { $ ptr = $ value ; break ; } elseif ( ! is_array ( $ ptr ) ) { $ ptr = array ( ) ; } } $ array = $ result ; }
Set the dotted key path in the array and return the value.

If any key already exists and is not an array, convert the key to an array so
that the value can be set.

@param array $array
@param string $keyPath
@param mixed $value The value to set in the array.

@return void
@throws BadKeyPath
Set the dotted key path in the array and return the value .