This website uses Cookies to provide you with the best possible service. Please see our Privacy Policy for more information. Click the check box below to accept cookies. Then confirm with a click on "Save".  
Status: 2023-12-28

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'