ArraySimple class

Framework\Helpers\ArraySimple

Class ArraySimple.

Contains methods to work with PHP arrays using "simple keys" (strings with
square brackets).

Simple key format example: `parent[child1][child2]`.

`user[country][state]` gets 'rs' in
`array('user' => ['country' => ['state' => 'rs']])`

Defined in libraries/helpers/src/ArraySimple.php

Methods #

convert()
Converts an array to an associative array with simple keys.
files()
Get $_FILES in a re-organized way.
keys()
Gets the keys of an array in the simple keys format.
revert()
Reverts an associative array of simple keys to an native array.
value()
Gets the value of an array item through a simple key.
addChild()
-
extractKeys()
-
filesWalker()
-
getChildKey()
-
getKeys()
-
getParentKey()
-

convert()

public static function convert(array $array): array

Converts an array to an associative array with simple keys.

Parameters
  • array $array - Array to be converted
Returns array - An associative array with the simple keys as keys and their corresponding values

files()

public static function files(?array $files = NULL): array

Get $_FILES in a re-organized way.

NOTE: Do not use file input names as `name`, `type`, `tmp_name`, `error`,
`full_path` and `size` to avoid overwrite of arrays.

Parameters
  • ?array $files
Returns array - An array ready to be used with {@see ArraySimple::value()}

keys()

public static function keys(array $array): array

Gets the keys of an array in the simple keys format.

Parameters
  • array $array - The array to get the simple keys
Returns array - An indexed array containing the simple keys as values

revert()

public static function revert(array $arraySimple): array

Reverts an associative array of simple keys to an native array.

Parameters
  • array $arraySimple - An array with simple keys
Returns array - An array with their corresponding values

value()

public static function value(string $simpleKey, array $array): mixed

Gets the value of an array item through a simple key.

Parameters
  • string $simpleKey - A string in the simple key format
  • array $array - The array to search in
Returns mixed - The item value or null if not found

addChild()

protected static function addChild(array &$parent, array $childs, mixed $value): void
Parameters
  • array $parent
  • array $childs
  • mixed $value
Returns void

extractKeys()

protected static function extractKeys(string $simpleKey): array
Parameters
  • string $simpleKey
Returns array

filesWalker()

protected static function filesWalker(array $array, string $infoKey): array
Parameters
  • array $array
  • string $infoKey
Returns array

getChildKey()

protected static function getChildKey(string $key): string
Parameters
  • string $key
Returns string

getKeys()

protected static function getKeys(array $array, string $childKey = ''): array
Parameters
  • array $array
  • string $childKey
Returns array

getParentKey()

protected static function getParentKey(string $key): ?string
Parameters
  • string $key
Returns ?string