Collection::map PHP Method

map() public method

Map a function to each item in the collection
public map ( function $callback ) : Collection
$callback function
return Collection
    public function map($callback)
    {
        $this->data = array_map($callback, $this->data);
        return $this;
    }

Usage Example

 public function testMap()
 {
     $this->collection->map(function ($item) {
         return sprintf('%s %s', $item['first_name'], $item['last_name']);
     });
     $this->assertEquals(['john smith', 'kara trace', 'phil mcKay', 'rose smith'], $this->collection->toArray());
 }
All Usage Examples Of Collection::map