Aplus Framework Docs

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
see
https://www.php.net/manual/en/language.types.array.php

Table of Contents

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.
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, mixed>

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

Return values
array<string, mixed>

An array ready to be used with ArraySimple::value()

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<int, string> &$parent, array<int, string> $childs, mixed $value) : void
Parameters
$parent : array<int, string>
$childs : array<int, string>
$value : mixed
Return values
void

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
see
https://stackoverflow.com/a/33261775/6027968
Return values
array<string, mixed>

getChildKey()

protected static getChildKey(string $key) : string
Parameters
$key : string
Return values
string

getKeys()

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
Return values
string|null

Search results