0%

Laravel mapSpread 例子

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$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());
x