Download the PHP package prowebcraft/dot without Composer
On this page you can find all versions of the php package prowebcraft/dot. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download prowebcraft/dot
More information about prowebcraft/dot
Files in prowebcraft/dot
Package dot
Short Description PHP dot notation array access
License MIT
Homepage https://github.com/prowebcraft/php-dot-notation
Informations about the package dot
Dot - PHP dot notation array access
Based on adbario/php-dot-notation package
Easy access to multidimensional arrays with dot notation. With dot notation, your code is cleaner and handling deeper arrays is super easy.
This class implements PHP's ArrayAccess class, so Dot object can also be used the same way as normal arrays with additional dot notation.
With Dot you can change this:
to this:
or even this:
Installation
Via composer:
Or just copy the class file Dot.php and handle namespace yourself.
With Composer:
Manual installation:
- Download the latest release
- Extract the files into your project
- require_once '/path/to/dot/src/Dot.php';
Usage
This array will be used as a reference on this guide:
Create a Dot object
To start with an empty array, just create a new Dot object:
If you have an array already available, inject it to the Dot object:
Set an array after creating the Dot object:
Set an array as a reference, and all changes will be made directly to the original array:
Set a value
Set i.e. a phone number in the 'home' array:
Set multiple values at once:
If the value already exists, Dot will override it with a new value.
Get a value
Get all the stored values:
php $address = $data->pull('home.address');
Get all the stored values and remove them:
### Add a value
Multiple values at once:
### Check if a value exists
### Delete a value
Multiple values at once:
### Clear values
Delete all the values from a path:
Clear multiple paths at once:
Clear all data:
### Sort the values
You can sort the values of a given path or all the stored values.
Sort the values of a path:
Sort all the values
### Magic methods
Magic methods can be used to handle single level data (without dot notation). These examples are not using the same data array as examples above.
Set a value:
Get a value:
Check if a value exists:
Delete a value:
## License
[MIT license](LICENSE.md)