Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- Collection::macro('join', function ($items, callable $callback) {
- return $this->map(function ($value) use ($items, $callback) {
- return $items->filter(function ($item) use ($value, $callback) {
- return $callback($value, $item);
- })->map(function ($item) use ($value) {
- return new Collection([$value, $item]);
- });
- })->flatten(1);
- });
- $first = collect([0, 1, 2]);
- $second = collect([0, 0, 1]);
- $result = $first->join($second, function ($a, $b) {
- return $a == $b;
- });
- dd($result);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement