laravel mapSpread 例子

 

$collection = collect(range(1, 9));

$chunks = $collection->chunk(2);

$labeld = $chunks->mapSpread(function ($odd, $even) {
    return "Odd: {$odd} Even: {$even}";
});

$numbers = collect([3, 5, 7]);
$words = collect(['three', 'five', 'seven']);

$results = $numbers->zip($words)
    ->mapSpread(function ($number, $word) {
        return $number . '=' . $word;
    });

dd($labeld->toArray(), $results->toArray());

  

 

posted @ 2019-01-04 10:53  佚名000  阅读(459)  评论(0编辑  收藏  举报