insert_unique()
insert_unique(array $arr, mixed $val) : array
A functon to test if an array element exists and if it does not, add the value specified.
Parameters
array | $arr | The input array |
mixed | $val |
Utility methods to deal with arrays.
key_exists_substr(array $arr, string $expr) : bool
A method to test if an array element exists by testing a subset of it's key.
array | $arr | The array to test |
string | $expr | The substring expression to test for |
todo |
---|
find_key_regexp(array $arr, string $expr) : mixed
Test if an array key exists, given a regular expression.
array | $arr | The array to search |
string | $expr | The regular expression to use in the search |
FALSE or actual key name.
todo |
---|
merge_by_keys(array $arr1, array $arr2, string $key1, string $key2)
Merge two arrays of hashes based on certain keys
array | $arr1 | The primary array |
array | $arr2 | The array to be merged |
string | $key1 | The key field in the first array |
string | $key2 | The key field in the second array |
todo |
---|
to_hash(array $input, string $key) : array
re-arrange an array of arrays into a hash of arrays by a specified key.
array | $input | The input array |
string | $key | The key to create the output array on |
todo |
---|
extract_field(array $input, string $key) : array
Extract one field from an array of hashes into a flat array
array | $input | The input associative array |
string | $key | The key to extract from the array of hashes |
todo |
---|
compare_elements_by_sortorder_key(array $e1, array $e2, string $key) : int
Compare two hashes by the key 'sort_key' This function is useful for sorting arrays of hashes.
array | $e1 | Associative Array 1 |
array | $e2 | Associative Array 2 |
string | $key | The key to sort each element by |
-1, 0, or -1
todo |
---|
hashsort(array $input, string $key, bool $is_string, bool $casecompare) : bool
Sort array of hashes by key
array | $input | An array of hashes. This array of hashes is sorted. |
string | $key | The hash key to sort by |
bool | $is_string | A boolean indicating if the key is a string |
bool | $casecompare | If $is_string is true, wether or not to do case sensitive comparisons |
todo |
---|
objsort(array $input, string $member, bool $is_string, bool $casecompare) : bool
Sort array of objects by member
array | $input | Arreay of objects to sort |
string | $member | The member name to sort on |
bool | $is_string | Indicates wether the member is a string |
bool | $casecompare | Wether the values should be sorted in a case sensitive, or case insensitive manner. |
todo |
---|
hashrsort(array $input, string $key, bool $is_string, bool $casecompare) : void
Sort array of hashes by key in reverse order
array | $input | The input array of hashes. This array is modified on output |
string | $key | The hash key to sort by |
bool | $is_string | Wether the value of the key is a string or not |
bool | $casecompare | If the value of the key is a string, wether it should be sorted in a case sensitive manner, or not. |
todo |
---|
explode_with_key(string $str, string $inglue, string $outglue) : array
Explode an array into a hash useful for separating params on a URL into a hash
string | $str | The input string. |
string | $inglue | inner glue string (separates name from value) |
string | $outglue | outer glue string (separates each variable/value combination) |
todo |
---|
find_index(array $data, mixed $needle) : \index
Given an array and a value, return the index of that value
array | $data | |
mixed | $needle |
or FALSE
todo |
---|
implode_with_key(\hash $assoc, string $inglue, string $outglue)
Implode a hash into an array suitable for forming a URL string with multiple key/value pairs
\hash | $assoc | input hash |
string | $inglue | inner glue |
string | $outglue | outer glue |
returns |
string; |
---|---|
todo |
implode_quoted(array $data, string $glue, string $quote) : string
Given an array, implode it into a string with non empty values quoted.
array | $data | The input array |
string | $glue | How each value should be separated in the input |
string | $quote | How non empty fields should be deliminated |
todo |
---|
to_object(\hash $array, bool $recursive) : \stdclass
Convert a hash into a stdclass object
\hash | $array | input array |
bool | $recursive | Wether or not to do recursive conversion |
object.
todo |
---|
hash_prepend(\hash $input, string $key, mixed $value) : \hash
Prepend a key/value pair to a hash.
This is useful when prepending an 'any' value to a list retrieved from the database, for use in filtering dialogs etc.
\hash | $input | input array |
string | $key | The key to prepend |
mixed | $value | The value to prepend |
todo |
---|
remove_by_value(array $input, string $value) : array
Remove All elements of the input array that have the specified value
array | $input | The input hash/array |
string | $value | The value to remove |
todo |
---|
is_hash( $arr) : bool
Test if the input array is an associative array (strings or something else for keys, instead of linearly increasing integers)
$arr |
todo |
---|
explode_to_tree(array $hash, string $delimiter, string $baseval)
Given a hash of records, where the key denotes the path separeted with a delimieter, generate a tree of records.
array | $hash | The input hash |
string | $delimiter | The identifier delimiter (used on hash keys) |
string | $baseval | Internal use only |
todo |
---|
smart_explode(string $str, string $delim, string $safe_char) : array
Smartly explode a string into an array given a delimiter, and a safe character.
Any instances of the delimiter inside two 'safe characters' will be included in the value.
This is useful when importing data from CSV.
string | $str | The input string |
string | $delim | The field delimeter |
string | $safe_char | The save character |
todo |
---|
search_recursive(array $input, string $needle) : mixed
Search a hash (recursively) to find an entry where the key specified is found
array | $input | A (potentially recursive) hash |
string | $needle | a member name |
The value of the found member
todo |
---|