lithium\util\Collection::map()
Applies a callback to a copy of all data in the collection and returns the result.
Parameters
-
callback
$filter
The filter to apply.
-
array
$options
The available options are:
'collect'
: Iftrue
, the results will be returned wrapped in a newCollection
object or subclass.
Returns
mixedThe filtered items. Will be an array unless 'collect'
is defined in the
$options
argument, then an instance of this class will be returned.
Links
Source
public function map($filter, array $options = []) {
$defaults = ['collect' => true];
$options += $defaults;
$data = array_map($filter, $this->_data);
if ($options['collect']) {
$class = get_class($this);
return new $class(compact('data'));
}
return $data;
}