Skip to content

Latest commit

 

History

History
26 lines (20 loc) · 837 Bytes

readme.md

File metadata and controls

26 lines (20 loc) · 837 Bytes

Dot Notation Array Access

version workflow license

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']);