Class Horde_Array

Description

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

$Horde: framework/Util/Array.php,v 1.26.2.12 2009/01/06 15:23:45 jan Exp $

Copyright 2003-2009 The Horde Project (http://www.horde.org/)

See the enclosed file COPYING for license information (LGPL). If you did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.

Located in /Util/Array.php (line 21)


	
			
Method Summary
 void arraySort (array &$array, [string $key = null], [integer $direction = 0], [boolean $associate = true])
 array array_merge_recursive_overwrite (array $a1, array $a2)
 mixed combine (array $keys, array $values)
 boolean getArrayParts (string $field, string &$base, array &$keys)
 mixed getElement (array &$array, array &$keys, [array $value = null])
 array getRectangle (array $array, integer $row, integer $col, integer $height, integer $width)
 array prepareAddressList (array $addr)
 integer sortAddressList (string $a, string $b)
 array valuesToKeys (array $array)
Methods
arraySort (line 93)

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

void arraySort (array &$array, [string $key = null], [integer $direction = 0], [boolean $associate = true])
  • array &$array: The array to be sorted, passed by reference.
  • string $key: The key by which to sort. If not specified then the first key is used.
  • integer $direction: Sort direction
    1. = ascending (default)
    2. = descending
  • boolean $associate: Keep key value association?
array_merge_recursive_overwrite (line 251)

Enhanced array_merge_recursive() function. Main difference from PHP's stock function is later value always overwrites earlier value (stock function will instead create an array with all values of key).

  • return: The merged array.
  • since: Horde 3.2
array array_merge_recursive_overwrite (array $a1, array $a2)
  • array $a1: The old array.
  • array $a2: The new array.
combine (line 222)

Creates an array by using one array for keys and another for its values. Only exists in PHP5, so we call array_combine if it exists and otherwise emulate it.

  • return: False if there are no elements, or the combined array.
mixed combine (array $keys, array $values)
  • array $keys: Key array.
  • array $values: Value array.
getArrayParts (line 128)

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.

  • return: True on sucess, false on error.
boolean getArrayParts (string $field, string &$base, array &$keys)
  • string $field: The field name to be examined.
  • string &$base: Set to the base element.
  • array &$keys: Set to the list of keys.
getElement (line 153)

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.

  • return: The final value of the key path.
mixed getElement (array &$array, array &$keys, [array $value = null])
  • array &$array: The array to be used.
  • array &$keys: The key path to follow as an array.
  • array $value: If set the target element will have this value set to it.
getRectangle (line 181)

Returns a rectangle of a two-dimensional array.

  • return: The extracted rectangle.
array getRectangle (array $array, integer $row, integer $col, integer $height, integer $width)
  • 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.
prepareAddressList (line 31)

Prepare a list of addresses for storage.

Namely, trims and lowercases all addresses and then sort.

  • return: The list of addresses, prepared for storage.
array prepareAddressList (array $addr)
  • array $addr: The list of addresses.
sortAddressList (line 55)

Function used by usort() to sort an address list.

e.g. usort($foo, array('Horde_Array', 'sortAddressList'));

  • return: -1, 0, or 1.
integer sortAddressList (string $a, string $b)
  • string $a: Address #1.
  • string $b: Address #2.
valuesToKeys (line 202)

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')

  • return: An array with keys the same as values.
array valuesToKeys (array $array)
  • array $array: An array of values.

Documentation generated on Sun, 30 Jan 2011 05:15:13 +0000 by phpDocumentor 1.4.3