Skip to content

Array Helper

Mattias edited this page Aug 1, 2021 · 1 revision

data_get()

The data_get function retrieves a value from a nested array or object using "dot" notation.

data_get($target, $key, $default)

Parameters

  • target (array/object) (Required)
  • key (string) (Required)
  • default (string) (Optional)

Example

$data = [
    'name' => 'John Doe',
    'age'  => 30,
    'kids' => [
        [
            'name' => [
                'firstname' => 'Iroh',
                'lastname'  => 'Git',
            ],
            'age'  => 12,
        ],
        [
            'name' => [
                'firstname' => 'Git',
                'lastname'  => 'hub',
            ],
            'age'  => 22,
        ],
    ],
];

$first_kid = arr()->data_get(
    $data
    'kids.0.name'
);
Clone this wiki locally