diff --git a/README.md b/README.md index 7067a15..8209fd6 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,18 @@ $point2d = new stdClass(); $point2d->x = 10; $point2d->y = 20; -$point3d = O::assoc('z', 30, $point2d); +$point3d = O::assoc('z', 30, $point2d); // {"x": 10, "y": 20, "z": 30} +``` + +- **dissoc** - removes a key from an object + +```php +$point3d = new stdClass(); +$point3d->x = 10; +$point3d->y = 20; +$point3d->z = 30; + +$point2d = O::dissoc('z', 30, $point3d); // {"x": 10, "y": 20} ``` ## Future plans diff --git a/src/O.php b/src/O.php index 27a9b6b..c7c9bfc 100644 --- a/src/O.php +++ b/src/O.php @@ -49,4 +49,10 @@ public static function assoc(string $key, $value, object $data): object { $data->{$key} = $value; return $data; } + + // O::dissoc('foo') + public static function dissoc(string $key, object $data): object { + unset($data->{$key}); + return $data; + } }