raziul/php-dot-array

Dot notation for PHP Array

0.5 2021-05-01 19:27 UTC

This package is auto-updated.

Last update: 2024-10-29 06:19:00 UTC


README

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.

Installation

The installation is simple using Composer

composer require raziul/php-dot-array

How to use?

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

Available Methods

Other than dot notation, this library also has some helper methods. These are the available methods:

Usage Example

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()

Suggestion/Issues

If you found any issues or have any suggestion then please create an issue.

You can also submit PR regarding any issues.

License

The MIT License (MIT). Please see License File for more information.