ArraySimple
in package
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']])
Tags
Table of Contents
Methods
- convert() : array<string, mixed>
- Converts an array to an associative array with simple keys.
- files() : array<string, mixed>
- Get $_FILES in a re-organized way.
- hasKey() : bool
- Checks if a simple key is present in an array.
- keys() : array<int, string>
- Gets the keys of an array in the simple keys format.
- revert() : array<string, mixed>
- Reverts an associative array of simple keys to an native array.
- value() : mixed
- Gets the value of an array item through a simple key.
- addChild() : void
- extractKeys() : array<int, string>
- filesWalker() : array<string, mixed>
- getChildKey() : string
- getKeys() : array<int, string>
- getParentKey() : string|null
Methods
convert()
Converts an array to an associative array with simple keys.
public
static convert(array<string|int, mixed> $array) : array<string, mixed>
Parameters
- $array : array<string|int, mixed>
-
Array to be converted
Return values
array<string, mixed> —An associative array with the simple keys as keys and their corresponding values
files()
Get $_FILES in a re-organized way.
public
static files([array<string|int, mixed>|null $files = null ]) : array<string, mixed>
NOTE: Do not use file input names as name, type, tmp_name, error,
full_path and size to avoid overwrite of arrays.
Parameters
- $files : array<string|int, mixed>|null = null
Return values
array<string, mixed> —An array ready to be used with ArraySimple::value()
hasKey()
Checks if a simple key is present in an array.
public
static hasKey(string $simpleKey, array<string|int, mixed> $array) : bool
Parameters
- $simpleKey : string
-
A string in the simple key format
- $array : array<string|int, mixed>
-
The array to check if the simple key is present
Return values
bool —True if the array has the simple key, otherwise false
keys()
Gets the keys of an array in the simple keys format.
public
static keys(array<string|int, mixed> $array) : array<int, string>
Parameters
- $array : array<string|int, mixed>
-
The array to get the simple keys
Return values
array<int, string> —An indexed array containing the simple keys as values
revert()
Reverts an associative array of simple keys to an native array.
public
static revert(array<string|int, mixed> $arraySimple) : array<string, mixed>
Parameters
- $arraySimple : array<string|int, mixed>
-
An array with simple keys
Return values
array<string, mixed> —An array with their corresponding values
value()
Gets the value of an array item through a simple key.
public
static value(string $simpleKey, array<string|int, mixed> $array) : mixed
Parameters
- $simpleKey : string
-
A string in the simple key format
- $array : array<string|int, mixed>
-
The array to search in
Return values
mixed —The item value or null if not found
addChild()
protected
static addChild(array<string|int, mixed> &$parent, array<string|int, mixed> $childs, mixed $value) : void
Parameters
- $parent : array<string|int, mixed>
- $childs : array<string|int, mixed>
- $value : mixed
extractKeys()
protected
static extractKeys(string $simpleKey) : array<int, string>
Parameters
- $simpleKey : string
Return values
array<int, string>filesWalker()
protected
static filesWalker(array<string|int, mixed> $array, string $infoKey) : array<string, mixed>
Parameters
- $array : array<string|int, mixed>
- $infoKey : string
Tags
Return values
array<string, mixed>getChildKey()
protected
static getChildKey(string $key) : string
Parameters
- $key : string
Return values
stringgetKeys()
protected
static getKeys(array<string|int, mixed> $array[, string $childKey = '' ]) : array<int, string>
Parameters
- $array : array<string|int, mixed>
- $childKey : string = ''
Return values
array<int, string>getParentKey()
protected
static getParentKey(string $key) : string|null
Parameters
- $key : string