adbario / php-dot-notation

Dot notation access to PHP arrays

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to access element of array

mikeerickson opened this issue · comments

Assuming you are loading from the ./composer.json file, how would one get the first element of the array

$value = $config->get('authors[0].name');
$value = $config->get('authors.0.name');

If i were accessing as an array,

$value = $array["authors"][0]["name"];

Have you tried these different ways to do it:

// Dot notation method
$value = $config->get('authors.0.name');

// Array reset() method
$value = reset($config->get('authors'));

// ArrayAccess method
$value = $config['authors][0]['name'];

should put it into readme~