Skip to content

aaleksu/array_aware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 

Repository files navigation

array_aware

php array structure aware lib

Provides a simple (even stupid) interface to work with an array.

Usage

Say, you have an array with relatively deep structure. For example, like this:

$aArray = [
    'a' => [
        'b' => [
            'c' => [
                'd' => [
                    'c' => 'value'
                ]
            ]
        ]
    ]
];

Surely you can get value of 'd' key by asking it directly:

$aArray['a']['b']['c']['d'];

It's OK but imagine you have to do it in several places (because of legacy (or because of prototyping), for example). You'd like to work with this array as with object. So you can do with ArrayAware:

$oArray = new ArrayAware($aArray);
$oArray->get('a/b/c/d'); // gives ['c' => 'value']
$oArray->get('a/b/c/www'); // gives null

It's important to remark that it's not a solution to use on a daily base, etc. It's just an example of how to make some difficult case a bit easier to work with.

About

php structure aware trait

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages