PHP Dot Array is a lightweight library that has few Helper methods for array and also provides an easy way of accessing arrays using Dot notation.
This is a standalone version of Laravel's Illuminate\Support\Arr.
The installation is simple using Composer
composer require raziul/php-dot-array
An example using regular syntax:
$data = [
'author' => [
'name' => 'Raziul Islam'
]
];
$data['author']['country']['name'] = 'Bangladesh';
echo $data['author']['country']['name']; // Bangladesh
Same example in dot array:
Arr::set($data, 'author.name', 'Raziul Islam');
Arr::set($data, 'author.country.name', 'Bangladesh');
echo Arr::get($data, 'author.country.name');
Other than dot notation, this library also has some helper methods. These are the available methods:
- accessible()
- add()
- collapse()
- crossJoin()
- divide()
- dot()
- except()
- exists()
- first()
- last()
- flatten()
- remove()
- get()
- has()
- hasAny()
- isAssoc()
- only()
- prepend()
- pull()
- random()
- set()
- shuffle()
- sortRecursive()
- query()
- where()
- wrap()
If you found any issues or have any suggestion then please create an issue.
You can also submit PR regarding any issues.
The MIT License (MIT). Please see License File for more information.