Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. <?php
  2.  
  3. Collection::macro('join', function ($items, callable $callback) {
  4. return $this->map(function ($value) use ($items, $callback) {
  5. return $items->filter(function ($item) use ($value, $callback) {
  6. return $callback($value, $item);
  7. })->map(function ($item) use ($value) {
  8. return new Collection([$value, $item]);
  9. });
  10. })->flatten(1);
  11. });
  12.  
  13. $first = collect([0, 1, 2]);
  14. $second = collect([0, 0, 1]);
  15.  
  16. $result = $first->join($second, function ($a, $b) {
  17. return $a == $b;
  18. });
  19.  
  20. dd($result);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement