Documentation

Horde_Array
in package

The Horde_Array:: class provides various methods for array manipulation.

Copyright 2003-2017 Horde LLC (http://www.horde.org/)

See the enclosed file LICENSE for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.

Tags
author

Michael Slusarz slusarz@horde.org

author

Marko Djukic marko@oblo.com

author

Jan Schneider jan@horde.org

category

Horde

license

http://www.horde.org/licenses/lgpl21 LGPL 2.1

Table of Contents

arraySort()  : mixed
Sorts an array on a specified key. If the key does not exist, defaults to the first key of the array.
getArrayParts()  : bool
Given an HTML type array field "example[key1][key2][key3]" breaks up the keys so that they could be used to reference a regular PHP array.
getElement()  : mixed
Using an array of keys iterate through the array following the keys to find the final key value. If a value is passed then set that value.
getRectangle()  : array<string|int, mixed>
Returns a rectangle of a two-dimensional array.
valuesToKeys()  : array<string|int, mixed>
Given an array, returns an associative array with each element key derived from its value.

Methods

arraySort()

Sorts an array on a specified key. If the key does not exist, defaults to the first key of the array.

public static arraySort(array<string|int, mixed> &$array[, string $key = null ], int $dir[, bool $assoc = true ]) : mixed
Parameters
$array : array<string|int, mixed>

The array to be sorted, passed by reference.

$key : string = null

The key by which to sort. If not specified then the first key is used.

$dir : int

Sort direction: 0 = ascending (default) 1 = descending

$assoc : bool = true

Keep key value association?

Return values
mixed

getArrayParts()

Given an HTML type array field "example[key1][key2][key3]" breaks up the keys so that they could be used to reference a regular PHP array.

public static getArrayParts(string $field, string &$base, array<string|int, mixed> &$keys) : bool
Parameters
$field : string

The field name to be examined.

$base : string

Will be set to the base element.

$keys : array<string|int, mixed>

Will be set to the list of keys.

Return values
bool

True on sucess, false on error.

getElement()

Using an array of keys iterate through the array following the keys to find the final key value. If a value is passed then set that value.

public static getElement(array<string|int, mixed> &$array, array<string|int, mixed> &$keys[, array<string|int, mixed> $value = null ]) : mixed
Parameters
$array : array<string|int, mixed>

The array to be used.

$keys : array<string|int, mixed>

The key path to follow as an array.

$value : array<string|int, mixed> = null

If set the target element will have this value set to it.

Return values
mixed

The final value of the key path.

getRectangle()

Returns a rectangle of a two-dimensional array.

public static getRectangle(array<string|int, mixed> $array, int $row, int $col, int $height, int $width) : array<string|int, mixed>
Parameters
$array : array<string|int, mixed>

The array to extract the rectangle from.

$row : int

The start row of the rectangle.

$col : int

The start column of the rectangle.

$height : int

The height of the rectangle.

$width : int

The width of the rectangle.

Return values
array<string|int, mixed>

The extracted rectangle.

valuesToKeys()

Given an array, returns an associative array with each element key derived from its value.

public static valuesToKeys(array<string|int, mixed> $array) : array<string|int, mixed>

For example: array(0 => 'foo', 1 => 'bar') would become: array('foo' => 'foo', 'bar' => 'bar')

Parameters
$array : array<string|int, mixed>

An array of values.

Return values
array<string|int, mixed>

An array with keys the same as values.

Search results