diff --git a/src/O.php b/src/O.php index 3b84536..f8251d2 100644 --- a/src/O.php +++ b/src/O.php @@ -58,6 +58,19 @@ public static function assoc(string $key, $value, $data) return $data; } + // O::assocPath(['foo', 'bar'], 12, {}) -> {foo: {bar: 12}} + function assocPath($path, $value, $data) { + $tmp = &$data; + + for ($i = 0; $i < count($path); $i++) { + $tmp = &$tmp[$path[$i]]; + } + + $tmp = $value; + + return $data; + } + // O::dissoc('foo', {foo: 'bar', fizz: 'buzz'}) -> {fizz: 'buzz'} public static function dissoc(string $key, $data) {