Overview

Namespaces

  • DSchoenbauer
    • DotNotation
      • Enum
      • Exception

Classes

  • ArrayDotNotation
  • Overview
  • Namespace
  • Class

Class ArrayDotNotation

An easier way to deal with complex PHP arrays

Namespace: DSchoenbauer\DotNotation
Author: David Schoenbauer
Version: 1.1.1
Located at DotNotation/ArrayDotNotation.php
Methods summary
public static static
# with( array $data = [] )

Sets the data to parse in a chain

Sets the data to parse in a chain

Parameters

$data
optional Array of data that will be accessed via dot notation.

Returns

static

Author

John Smart
David Schoenbauer
public
# __construct( array $data = [] )

An alias for setData

An alias for setData

Parameters

$data
optional Array of data that will be accessed via dot notation.

Since

1.0.0

See

DSchoenbauer\DotNotation\ArrayDotNotation::setData()
public array
# getData( )

returns the array

returns the array

returns the array that the dot notation has been used on.

Returns

array
Array of data that will be accessed via dot notation.

Since

1.0.0
public
# setData( array $data )

sets the array that the dot notation will be used on.

sets the array that the dot notation will be used on.

Parameters

$data
Array of data that will be accessed via dot notation.

Returns


$this

Since

1.0.0
public mixed
# get( string $dotNotation, mixed $defaultValue = null )

Retrieves a value from an array structure as defined by a dot notation string

Retrieves a value from an array structure as defined by a dot notation string

Returns a value from an array.

Parameters

$dotNotation
a string of keys concatenated together by a dot that represent different levels of an array
$defaultValue
value to return if the dot notation does not find a valid key

Returns

mixed
value found via dot notation in the array of data

Since

1.0.0
protected mixed
# recursiveGet( array $data, array $keys, mixed $defaultValue )

Recursively works though an array level by level until the final key is found. Once key is found the keys value is returned.

Recursively works though an array level by level until the final key is found. Once key is found the keys value is returned.

Parameters

$data
array that has value to be retrieved
$keys
array of keys for each level of the array
$defaultValue
value to return when a key is not found

Returns

mixed
value that the keys find in the data array

Since

1.0.0
public
# set( string $dotNotation, mixed $value )

sets a value into a complicated array data structure

sets a value into a complicated array data structure

Places a value into a tiered array. A dot notation of "one.two.three" would place the value at ['one' => ['two' => ['three' => 'valueHere' ]]] If the array does not exist it will be added. Indexed arrays can be used, and referenced by number. i.e. "one.0" would return the first item of the one array.

Parameters

$dotNotation
dot notation representation of keys of where to set a value
$value
any value to be stored with in a key structure of dot notation

Returns


$this

Throws

DSchoenbauer\DotNotation\Exception\PathNotArrayException
if a value in the dot notation path is not an array

Since

1.0.0
protected
# recursiveSet( array & $data, array $keys, mixed $value )

Transverses the keys array until it reaches the appropriate key in the data array and sets that key to the value. If the keys don't exist they are created.

Transverses the keys array until it reaches the appropriate key in the data array and sets that key to the value. If the keys don't exist they are created.

Parameters

$data
data to be traversed
$keys
the remaining keys of focus for the data array
$value
the value to be placed at the final key

Throws

DSchoenbauer\DotNotation\Exception\PathNotArrayException
if a value in the dot notation path is not an array

Since

1.0.0
public
# merge( string $dotNotation, array $value )

Merges two arrays together over writing existing values with new values, while adding new array structure to the data

Merges two arrays together over writing existing values with new values, while adding new array structure to the data

Parameters

$dotNotation
dot notation representation of keys of where to set a value
$value
array to be merged with an existing array

Returns


$this

Throws

DSchoenbauer\DotNotation\Exception\UnexpectedValueException
if a value in the dot notation path is not an array
DSchoenbauer\DotNotation\Exception\TargetNotArrayException
if the value in the dot notation target is not an array

Since

1.1.0
public
# remove( string $dotNotation )

Removes data from the array

Removes data from the array

Parameters

$dotNotation
dot notation representation of keys of where to remove a value

Returns


$this

Since

1.1.0
protected
# recursiveRemove( array & $data, array $keys )

Transverses the keys array until it reaches the appropriate key in the data array and then deletes the value from the key.

Transverses the keys array until it reaches the appropriate key in the data array and then deletes the value from the key.

Parameters

$data
data to be traversed
$keys
the remaining keys of focus for the data array

Throws

DSchoenbauer\DotNotation\Exception\UnexpectedValueException

if a value in the dot notation path is not an array

Since

1.1.0
protected array
# getKeys( type $notation )

consistently parses notation keys

consistently parses notation keys

Parameters

$notation
key path to a value in an array

Returns

array
array of keys as delimited by the notation type
public string
# getNotationType( )

Returns the current notation type that delimits the notation path. Default: "."

Returns the current notation type that delimits the notation path. Default: "."

Returns

string
current notation character delimiting the notation path
public
# setNotationType( string $notationType = "." )

Sets the current notation type used to delimit the notation path.

Sets the current notation type used to delimit the notation path.

Parameters

$notationType

Returns


$this
public boolean
# has( string $dotNotation )

Checks to see if a dot notation path is present in the data set.

Checks to see if a dot notation path is present in the data set.

Parameters

$dotNotation
dot notation representation of keys of where to remove a value

Returns

boolean
returns true if the do notation path exists in the data
API documentation generated by ApiGen