Download the PHP package noj/dot without Composer
On this page you can find all versions of the php package noj/dot. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package dot
Short Description Nested array/object access through dot notation
License MIT
Informations about the package dot
Dot
Dot allows you to get & set array keys or object properties using dot notation.
Installing
Usage
First construct a new Dot instance:
All the examples are using the following data structure unless otherwise specified:
Methods
- count
- find
- first
- get
- has
- push
- set
Dot::count(string $path): int
Count the number of items at a given path.
Dot::find(string $path, mixed $equals): Dot
Find items that pass the given truth test.
Dot::first(string $path, mixed $equals): Dot
Find the first item that passes the given truth test.
Dot::get(null|int|string $path): mixed
Access nested array keys and object properties using dot syntax:
Dot safely returns null if the key or property doesn't exist:
You can use a wildcard *
to pluck values from multiple paths:
You can call functions using the @
prefix:
If no argument is passed it will return the underlying data:
Dot::has(string $path): bool
Returns true if path exists, false otherwise:
Dot::push(string $path, mixed $value): Dot
Push a value onto an existing array:
Dot::set(array|string $paths, mixed $value): void
You can set nested values using the same syntax:
Set nested keys from multiple paths using a wildcard *
:
Keys will be created if they don't already exist:
By default, set will initialise missing values as empty arrays. To indicate that something should be an object use the ->
delimiter:
You can set multiple values at once by passing an array:
You can call a method:
Or call a method for each value of an array:
Non-chained versions
All methods have non-chained versions of themselves as a standalone function, i.e: