Skip to content

iRaziul/php-dot-array

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Dot Array - Access array using dot notation in PHP

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.

About

Dot notation array for PHP

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages