Skip to content

Instantly share code, notes, and snippets.

@lorenzo
Created September 22, 2015 07:37
Show Gist options
  • Save lorenzo/9198544013a9ca067689 to your computer and use it in GitHub Desktop.
Save lorenzo/9198544013a9ca067689 to your computer and use it in GitHub Desktop.
<?php
collection($items)
// I only care about elements having the id = a or id = b
->filter(function ($value, $key) use ($array) {
return isset($array[$value['id']]); // If the key is in the array, the it should be kept in the collection
})
/// Let's now index the collection by the id
->groupBy('id')
// Finally, let's reduce the collection to list of strings per key
->reduce(function ($result, $value) {
return $result . ', ' . $value['title'];
}, '')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment