-
Hash::get($data, $path, $default = NULL);
get() is a simplified version of extract(), it
only supports direct path expressions. Paths with {n}, {s}
or matchers are not supported. Use get() when you want exactly
one value out of an array. The optional third argument will be returned if
the requested path is not found in the array.
[Docs]
-
Hash::insert($data, $path, $values = NULL);
Inserts $data into an array as defined by $path
[Docs]
-
Hash::remove($data, $path);
Removes all elements from an array that match $path.
[Docs]
-
Hash::combine($data, $keyPath, $valuePath = NULL, $groupPath = NULL);
Creates an associative array using a $keyPath as the path to
build its keys, and optionally $valuePath as path to get the values. If
$valuePath is not specified, or doesn’t match anything, values
will be initialized to null. You can optionally group the values by what is
obtained when following the path specified in $groupPath.
[Docs]
-
Hash::format($data, $paths, $format);
Returns a series of values extracted from an array, formatted with a format string.
[Docs]
-
Hash::contains($data, $needle);
RDetermines if one Hash or array contains the exact keys and values of another.
[Docs]
-
Hash::check($data, $path = NULL);
Checks if a particular path is set in an array.
[Docs]
-
Hash::filter($data, $callback = array('Hash', 'filter'));
Filters empty elements out of array, excluding ‘0’. You can
also supply a custom $callback to filter the array elements.
Your callback should return false to remove elements from
the resulting array.
[Docs]
-
Hash::flatten($data, $separator = '.');
Collapses a multi-dimensional array into a single dimension.
[Docs]
-
Hash::expand($data, $separator = '.');
Expands an array that was previously flattened with Hash::flatten().
[Docs]
-
Hash::merge($data, $merge[, array $n]);
This function can be thought of as a hybrid between PHP’s array_merge and array_merge_recursive. The difference to the two is that if an array key contains another array then the function behaves recursive (unlike array_merge) but does not do if for keys containing strings (unlike array_merge_recursive).
[Docs]
-
Hash::numeric($data);
Checks to see if all the values in the array are numeric.
[Docs]
-
Hash::dimensions($data);
Counts the dimensions of an array. This method will only consider the dimension of the first element in the array.
[Docs]
-
Hash::maxDimensions($data);
Similar to dimensions(), however this method returns, the deepest number of dimensions of any element in the array.
[Docs]
-
Hash::map($data, $path, $function);
Creates a new array, by extracting $path, and mapping $function across the results. You can use both expression and matching elements with this method.
[Docs]
-
Hash::reduce($data, $path, $function);
Creates a single value, by extracting $path, and reducing the extracted results with $function. You can use both expression and matching elements with this method.
[Docs]
-
Hash::apply($data, $path, $function);
Apply a callback to a set of extracted values using $function. The function will get the extracted values as the first argument.
[Docs]
-
Hash::sort($data, $path, $dir, $type = 'regular');
Sorts an array by any value, determined by a Hash path syntax Only expression elements are supported by this method.
[Docs]
$dir can be either asc or desc. $type can be one of the following values:
regular for regular sorting
numeric for sorting values as their numeric equivalents
string for sorting values as their string value
natural for sorting values in a human friendly way. Will sort foo10 below foo2 as an example. Natural sorting requires PHP 5.4 or greater
-
Hash::diff($data, $compare);
Computes the difference between two arrays.
[Docs]
-
Hash::mergeDiff($data, $compare);
This function merges two arrays and pushes the differences in data to the bottom of the resultant array.
[Docs]
-
Hash::normalize($data, $assoc = TRUE);
Normalizes an array. If $assoc is true, the resulting array will be normalized to be an associative array. Numeric keys with values, will be converted to string keys with null values. Normalizing an array, makes using the results with Hash::merge() easier.
[Docs]
-
Hash::nest($data, $options = array());
Takes a flat array set, and creates a nested, or threaded data structure. Used by methods like Model::find('threaded').
[Docs]
Options:
children The key name to use in the result set for children. Defaults to ‘children’.
idPath The path to a key that identifies each entry. Should be compatible with Hash::extract(). Defaults to {n}.$alias.id
parentPath The path to a key that identifies the parent of each entry. Should be compatible with Hash::extract(). Defaults to {n}.$alias.parent_id
root The id of the desired top-most result.