codin / dot
Dot Notation Array Access
Installs: 6 960
Dependents: 2
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 1
Requires
- php: >=7.3
Requires (Dev)
- friends-of-phpspec/phpspec-code-coverage: @stable
- friendsofphp/php-cs-fixer: @stable
- phpspec/phpspec: @stable
- phpstan/phpstan: @stable
This package is auto-updated.
Last update: 2024-10-22 11:28:33 UTC
README
Fetching array items by dot notation
$dot = new Codin\Dot(['foo' => ['bar' => 'baz']]); $dot->get() // ['foo' => ['bar' => 'baz']] $dot->get('foo') // ['bar' => 'baz'] $dot->get('foo.bar') // 'baz' $dot->get('foo.bar.qux') // null $dot->get('foo.bar.qux', 'hello') // 'hello'
$dot->set('foo.bar', 'qux'); $dot->get() // ['foo' => ['bar' => 'qux']] $dot->set('foo.bar.baz', 'qux'); // throws DotException the value at the index is not an array and wont be converted. // Instead store the value as an array to overwrite $dot->set('foo.bar', ['baz' => 'qux']);