Skip to content

Latest commit

 

History

History
100 lines (80 loc) · 1.36 KB

File metadata and controls

100 lines (80 loc) · 1.36 KB

ArrDot - [array dot notation]

with ArrDot you can access arrays via dot notation.


Instantiate

$oArrDot = new ArrDot(array $aArray);

create a new instance of ArrDot

$oArrDot = new ArrDot(
    array( 
        'user' => [
            'foo' => 'bar',
            'john' => 'doe'
        ],
        'etc' => [
            'OS' => 'Linux'
        ]       
    )
);

set

$oArrDot->set(string $sKey, mixed);

add a key/value by set method

$oArrDot->set('user.mary', 'moo');

get

$oArrDot->get();
$oArrDot->get(string $sKey);

get complete array

$aMyArray = $oArrDot->get();
// type: array, items: 2
[
    'user' => [
        'foo' => 'bar',
        'john' => 'doe',
        'mary' => 'moo',
    ],
    'etc' => [
        'OS' => 'Linux',
    ],
]

get value on an existing key

$oArrDot->get('user.john')
// type: string
'doe'

getIndexOnValue

searches for a value in given array; returns dot notation address on the first hit.

get key on existing value

$oArrDot->getIndexOnValue('Linux')
// type: string
'etc.OS'