Created
September 22, 2015 07:37
-
-
Save lorenzo/9198544013a9ca067689 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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