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.
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.
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.
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:
$foo =
Hashtable::merge(array(0 =>
'a', 'a' =>
'a'), array(0 =>
'b'), 1 =>
'c');
Result:
array (
0 => 'b',
'a' => 'a',
1 => 'c'
)
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:
Result:
array (
0 => 1,
1 => array(
0 => 'c',
1 => 2,
'a' => 'b'
),
2 => 3
)
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.
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.
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.
inherited from base classes
Inherited From Utility