yana

phpDocumentor v 1.4.0

Class Hashtable

Description

«utility» Hashtable
This is a static utility class to implement certain operations on hashtables (associative arrays).
Example for usage of the $key parameter:
 Array {
     ID1 => Array {
         ID2 => 'value'
     }
 }
To get the string 'value' from the hashtable above use $key = 'ID1.ID2'
The wildcard '*' may be used to refer to the hashtable as a whole.
  • access: public
Utility
   |
   --Hashtable
Method Summary
  • array changeCase (array $input, [int|bool $case = CASE_LOWER])
  • bool exists (array &$hash, string $key)
  • mixed &get (array &$hash, string $key)
  • array merge (array $A, array $B)
  • bool remove (array &$hash, string $key)
  • bool set (array &$hash, string $key, mixed $value)
  • bool setByReference (array &$hash, string $key, mixed &$value)
  • bool setType (array &$hash, string $key, string $type)

Methods

Lowercase or uppercase all keys of an associative array
array changeCase (
array $input, [int|bool $case = CASE_LOWER]
)
List of parameters:
Name Type Description
$input array input array
$case int|bool CASE_UPPER or CASE_LOWER
Description:
This is a recursive implementation of the PHP function array_change_key_case(). It takes the same arguments: an array $input to work on and an optional argument $case. The argument $case can be one of two constants: CASE_LOWER and CASE_UPPER, where CASE_LOWER is the default.
  • access: public
check if an element exists
bool exists (
array &$hash, string $key
)
List of parameters:
Name Type Description
&$hash array associative array
$key string address
Description:
Returns bool(false) if the element identified by $key can not be found in the given hashtable or it is NULL. Returns bool(true) otherwise.
  • access: public
retrieve a value
mixed &get (
array &$hash, string $key
)
List of parameters:
Name Type Description
&$hash array associative array
$key string address
Description:
Finds the value identified by $key and returns it. If the value is not found NULL is returned.
  • access: public
recursively merge two arrays to one
array merge (
array $A, array $B
)
List of parameters:
Name Type Description
$A array base array
$B array merge with this array
Description:
This function is pretty much the same as the php function "array_merge_recursive" except for the way how duplicate keys are treated. Dupplicate keys get replaced in this implementation rather than being appended.
You may provide two or more arrays to merge.
Example with 2 arrays:
  1.  $foo Hashtable::merge(array(=> 'a''a' => 'a')array(=> 'b')=> 'c');
Result:
 array (
 0 => 'b',
 'a' => 'a',
 1 => 'c'
 )
Example with 4 arrays:
  1.  $bar Hashtable::merge($a1$a2$a3$a4);
Recursive example:
 $a1 = array (
 0 => 1,
 1 => array(
   0 => 1,
   'a' => 'b'
   )
 );
 $b = array (
 1 => array(
   0 => 'c',
   1 => 2,
   )
 );
 2 => 3,
Compute this via:
  1.  $foobar Hashtable::merge($a1$a2);
Result:
 array (
 0 => 1,
 1 => array(
   0 => 'c',
   1 => 2,
   'a' => 'b'
   ),
 2 => 3
 )
  • access: public
remove an element
bool remove (
array &$hash, string $key
)
List of parameters:
Name Type Description
&$hash array associative array
$key string address
Description:
Unsets the element identified by $key in the hashtable. Returns bool(false) if the element does not exist or the key is invalid. Returns bool(true) otherwise.
  • access: public
set an element to a value
bool set (
array &$hash, string $key, mixed $value
)
List of parameters:
Name Type Description
&$hash array associative array
$key string address
$value mixed some new value
Description:
Sets the element identified by $key to $value. If the value does not exist it gets inserted. If a previous value existed the value gets updated.
This function returns bool(false) if $key = '*' and $value is not an array - which is: trying overwrite the complete hashtable with a non-array value. It returns bool(true) otherwise.
set an element by Reference
bool setByReference (
array &$hash, string $key, mixed &$value
)
List of parameters:
Name Type Description
&$hash array associative array
$key string address
&$value mixed some new value
Description:
Sets the element identified by $key to $value by passing it's reference. If the value does not exist it gets inserted. If a previous value existed the value gets updated.
This function returns bool(false) if $key = '*' and $value is not an array - which is: trying overwrite the complete hashtable with a non-array value. It returns bool(true) otherwise.
  • see: Hashtable::set()
  • since: 2.8.5
  • access: public
  • name: Hashtable::setByReference()
set the data type of an element
bool setType (
array &$hash, string $key, string $type
)
List of parameters:
Name Type Description
&$hash array associative array
$key string address
$type string data type
Description:
Set the data type of the element identified by $key to $type.
Returns bool(false) if the element is NULL or does not exist, or the $type parameter is invalid. Returns bool(true) otherwise.
  • access: public
inherited from base classes

Inherited From Utility

Documentation generated on Sat, 03 Jan 2009 22:22:27 +0100 by phpDocumentor 1.4.0

yana author: Thomas MeyerHomepage: www.yanaframework.net