$data
$data : array
add(string $key, mixed $value) : \Obs\Common\Collection
Add a value to a key. If a key of the same name has already been added, the key value will be converted into an array and the new value will be pushed to the end of the array.
string | $key | Key to add |
mixed | $value | Value to add to the key |
Returns a reference to the object.
map(\Closure $closure, array $context = array(), boolean $static = true) : \Obs\Common\Collection
Returns a Collection containing all the elements of the collection after applying the callback function to each one. The Closure should accept three parameters: (string) $key, (string) $value, (array) $context and return a modified value
\Closure | $closure | Closure to apply |
array | $context | Context to pass to the closure |
boolean | $static | Set to TRUE to use the same class as the return rather than returning a Collection |
filter(\Closure $closure, boolean $static = true) : \Obs\Common\Collection
Iterates over each key value pair in the collection passing them to the Closure. If the Closure function returns true, the current value from input is returned into the result Collection. The Closure must accept three parameters: (string) $key, (string) $value and return Boolean TRUE or FALSE for each value.
\Closure | $closure | Closure evaluation function |
boolean | $static | Set to TRUE to use the same class as the return rather than returning a Collection |
setPath(string $path, mixed $value) : self
Set a value into a nested array key. Keys will be created as needed to set the value.
string | $path | Path to set |
mixed | $value | Value to set at the key |
when trying to setPath using a nested path that travels through a scalar value
getPath(string $path, string $separator = '/', mixed $data = null) : mixed|null
Gets a value from the collection using an array path (e.g. foo/baz/bar would retrieve bar from two nested arrays) Allows for wildcard searches which recursively combine matches up to the level at which the wildcard occurs. This can be useful for accepting any key of a sub-array and combining matching keys from each diverging path.
string | $path | Path to traverse and retrieve a value from |
string | $separator | Character used to add depth to the search |
mixed | $data | Optional data to descend into (used when wildcards are encountered) |