\Horde_Array

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.

Summary

Methods
Properties
Constants
arraySort()
getArrayParts()
getElement()
getRectangle()
valuesToKeys()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

arraySort()

arraySort(array  $array, string  $key = null, integer  $dir, boolean  $assoc = true) 

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

Parameters

array $array
string $key

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

integer $dir

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

boolean $assoc

Keep key value association?

getArrayParts()

getArrayParts(string  $field,   $base,   $keys) : boolean

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.

Parameters

string $field

The field name to be examined.

$base
$keys

Returns

boolean —

True on sucess, false on error.

getElement()

getElement(  $array, array  $keys, array  $value = null) : 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.

Parameters

$array
array $keys
array $value

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

Returns

mixed —

The final value of the key path.

getRectangle()

getRectangle(array  $array, integer  $row, integer  $col, integer  $height, integer  $width) : array

Returns a rectangle of a two-dimensional array.

Parameters

array $array

The array to extract the rectangle from.

integer $row

The start row of the rectangle.

integer $col

The start column of the rectangle.

integer $height

The height of the rectangle.

integer $width

The width of the rectangle.

Returns

array —

The extracted rectangle.

valuesToKeys()

valuesToKeys(array  $array) : array

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

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

Parameters

array $array

An array of values.

Returns

array —

An array with keys the same as values.