Skip to content

Latest commit

 

History

History
51 lines (34 loc) · 1.24 KB

README.md

File metadata and controls

51 lines (34 loc) · 1.24 KB

Delimiter Array Access

Delimiter array access is a function that allows for the finding of array values by dot notation.

Sometimes it's just easier to read accessing array chains by a string with a delimiter. Instead of compound, chained accessors that may lead to unexpected errors this function is null safe. This isn't trying to be fast. It's trying to provide developers options in how they want their code read.

Descripton

delimiter_array_access( string $needle, array $haystack, [ string $delimiter = '.' ] ) : mixed

Installation

$ composer require william-lindner/delimiter_array_access

Parameters

needle (Required)

The string with delimiter you want parsed to extract the value from the array.

haystack (Required)

The array being parsed to find the value.

delimiter (Optional)

The optional delimiter for the string needle, defaulting to a period.

Example

In the following example the value nested within the array is extracted using the default delimiter of a period.

$myArray = [
  'my' => [
    'assoc' => [
      'array' => 'I found a value.'
    ]
  ]
];

// This will output 'I found a value.'
echo delimiter_array_access('my.assoc.array', $myArray) . PHP_EOL;